/*
 * Copyright (c) 2010-2020 DMGIS Ltd. All Rights Reserved.
 *
 * This software is the confidential and proprietary information of
 * DMGIS. You shall not disclose such Confidential Information
 * and shall use it only in accordance with the terms of the agreements
 * you entered into with DMGIS.
 *
 */
package com.dmgis.qxfw.dataservice.businessservice.qxinfo.controller;


import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import com.alibaba.fastjson.serializer.SerializerFeature;
import com.dmgis.entity.DmMapRectangle;
import com.dmgis.entity.DmMapPoint;
import com.dmgis.qxfw.dataservice.businessservice.api.domain.DbConfig;
import com.dmgis.qxfw.dataservice.businessservice.api.entity.Results;
import com.dmgis.qxfw.dataservice.businessservice.api.entity.qx.*;
import com.dmgis.qxfw.dataservice.businessservice.api.entity.xt.sys_config;
import com.dmgis.qxfw.dataservice.businessservice.api.entity.zy.river_basin;
import com.dmgis.qxfw.dataservice.businessservice.api.entity.zy.thunder_fcst;
import com.dmgis.qxfw.dataservice.businessservice.common.domain.*;
import com.dmgis.qxfw.dataservice.businessservice.common.entity.*;
import com.dmgis.qxfw.dataservice.businessservice.common.service.IConfigService;
import com.dmgis.qxfw.dataservice.businessservice.common.util.*;
import com.dmgis.qxfw.dataservice.businessservice.dmgis_mongodb_srv.dataservice.service.Impl.FileRequestService;
import com.dmgis.qxfw.dataservice.businessservice.dmgis_mongodb_srv.dataservice.service.Impl.MongoService1;
import com.dmgis.qxfw.dataservice.businessservice.qxinfo.pojo.WeatherVo;
import com.dmgis.qxfw.dataservice.businessservice.qxinfo.service.IQxInfoService;
import com.dmgis.qxfw.dataservice.businessservice.qxinfo.service.IQxSmallScaleService;
import com.dmgis.qxfw.dataservice.businessservice.yyjt.service.IForecastInfoService;
import com.dmgis.qxfw.dataservice.businessservice.yysl.service.IWaternfoService;
import com.dmgis.qxfw.dataservice.businessservice.cdyj.service.IEmergencyService;
import com.dmgis.qxfw.dataservice.gisservice.service.ITransformService;
import com.dmgis.qxfw.dataservice.pages.service.IComDisplayService;
import com.dmgis.service.DmServiceConnector;
import com.dmgis.weblib.GridAnalysis;
import com.dmgis.weblib.MapCommon;
import com.dmgis.weblib.MapProj;
import com.dmgis.weblib.MapProjPara;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import java.awt.geom.Point2D;
import java.io.*;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.List;
import java.util.*;

/**
 * This class is used for 气象信息展示控制层
 *
 * @author dsq
 * @version 1.0, 2018年10月28日 下午12:29:00
 */
@Controller
@RequestMapping("/qxinfo")
public class QxLiveInfoController {
    private  final String operatingSystem;

    @Autowired
    public QxLiveInfoController(String operatingSystem) {
        this.operatingSystem = operatingSystem;
    }
    @Resource
    private IQxInfoService qxInfoService;
    @Resource
    private IConfigService configService;
    @Resource
    private IForecastInfoService forecastInfoService;
    @Resource
    private IQxSmallScaleService skInfoService;
    @Autowired
    private IComDisplayService comDisplayService;
    @Resource
    IEmergencyService emergencyService;
    @Resource
    private IWaternfoService waternfoService;

    @Resource
    private ITransformService transformService;

    //MongoService1 ms = new MongoService1();
     FileRequestService ms = new FileRequestService();
    DmServiceConnector conn = new DmServiceConnector("127.0.0.1", "6163");

    /**
     * 初始化雷达图页面
     * 2
     *
     * @return
     * @author dsq
     * @date 2018年7月6日
     */
    @RequestMapping("/initRadarPage")
    @ResponseBody
    public Object  initRadarPage() throws ParseException {
        ArrayList<Object> arrayList = new ArrayList<Object>();
        String type = "LD";
        // 获取时间
         collectTime scaleNewDate = qxInfoService.getScaleNewDate(type);
        StringBuilder dateTime = new StringBuilder();
        dateTime.append(scaleNewDate.getYear() + "-");
        dateTime.append(scaleNewDate.getMonth() + "-");
        dateTime.append(scaleNewDate.getDay() + " ");
        dateTime.append(scaleNewDate.getHour());

        SimpleDateFormat sdf2 = new SimpleDateFormat("yyyy-MM-dd HH");
        Date d1 = sdf2.parse(dateTime.toString());
        // 加载列表
        DateTime date = new DateTime(d1);
        String endDate = date.toDateTimeString();
        String startDate = date.AddHours(-1).toDateTimeString();
        arrayList.add(startDate);
        arrayList.add(endDate);
        String paramType1 = "雷达站";

        String paramType2 = "雷达配置";
//        String paramType2 = "雷达参数";
        arrayList.add(configService.getSysConfig(paramType1));// 添加雷达站信息
        arrayList.add(configService.getSysConfig(paramType2));// 添加雷达站信息
        SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
        Date doppleTime = sdf.parse(dateTime.toString());
        List<DopplerKey> dKey2 = qxInfoService.getRadarTypes(doppleTime);
        for (DopplerKey dop : dKey2) {
            dop.setType(DbConfig.getRaderType(dop.getType()));
        }
        arrayList.add(dKey2);
        return arrayList;
    }


    /**
     * @throws
     * @return2
     * @author dsq
     * @date 2018年7月6日
     */
    @RequestMapping("/getRadarInfo")
    @ResponseBody
    public Object getRadarInfo(HttpServletRequest request, Model model) throws ParseException, IOException {

        String stationId = request.getParameter("stationId");
        String startDate = request.getParameter("startDate");
        String endDate = request.getParameter("endDate");
        String type = request.getParameter("type");

        switch (type) {
            case "基本反射率图19":
                type = "19";
                break;
            case "基本反射率图20":
                type = "R20";
                break;
            case "基本速度26":
                type = "26";
                break;
            case "基本速度27":
                type = "27";
                break;
            case "组合反射率图37":
                type = "CR37";
                break;
            case "组合反射率图38":
                type = "38";
                break;
            default:

                break;  // 确保这里有 break，防止误执行默认情况之外的代码
        }
        String elevation = request.getParameter("elevation");
        RadarSearch dKey = new RadarSearch();
        dKey.setStationId(stationId);
        dKey.setStartDate(DateTime.parseDateTime(startDate).toDateTimeString());
        dKey.setEndDate(DateTime.parseDateTime(endDate).toDateTimeString());
        dKey.setType(type);
        if (!StringUtil.IsNullOrEmpty(elevation)) {
            dKey.setElevation(Float.parseFloat(elevation));
        }
        List<Doppler> resultList = qxInfoService.getRadarInfo(dKey);

        for (Doppler doppler : resultList) {
            String fileName = DbConfig.getRadarFileName(doppler.getType(), String.valueOf(doppler.getElevation()),
                    doppler.getStationId(), doppler.getDateChar(), doppler.getTimeChar()) + ".png";
            String serviceFilePath = "";
//            String path = request.getContextPath();
            String basePath =  "/Temp/radar/";
            String serviceUrl = basePath + fileName;
            String urlpath1 ;
            if (operatingSystem.equals("Windows")){
                 urlpath1 = request.getSession().getServletContext().getRealPath("/") + "Temp\\radar\\";
            }else {
                 urlpath1 = request.getSession().getServletContext().getRealPath("/") + "Temp/radar/";
            }

            serviceFilePath = urlpath1 + fileName;// 服务器文件
            FileUtil.mkDirs(urlpath1);// 创建文件夹，生成多级目录
            FileUtil.ClearTempFiles(urlpath1, 1000);// 清除缓存
            // 如果目录中不存在文件，下载雷达文件到temp目录
            File serviceFile = new File(serviceFilePath);// 服务器文件
            if (!serviceFile.exists()) {
                // 从mongdb获取图片
                Map<String, Object> map = new HashMap<String, Object>();
                map.put("dateyear", new DateTime(doppler.getDateChar()).toDateString().substring(0, 4));
                map.put("datechar", new DateTime(doppler.getDateChar()).toDateString());
                map.put("stationid", doppler.getStationId() == null ? doppler.getStationId() : doppler.getStationId().toString());
                String elev = doppler.getElevation().toString();
                // String elevsString = (doppler.getElevation() - (int) elev) == 0 ? String.valueOf((int) elev) : String.valueOf(doppler.getElevation());
                map.put("elevation", elev);
                map.put("ldtype", doppler.getType());
                map.put("timechar", doppler.getTimeChar() == null ? doppler.getTimeChar() : doppler.getTimeChar().toString());
                //map.put("type", "ld_png_file_m");
                map.put("collectionName", "ld_png_file");
                byte[] data = ms.selectData(map);
                if (data == null) {
                    serviceFilePath = "";
                } else {
                    FileUtil.bytesToFile(data, serviceFilePath);
//                    doppler.setJwImgPath("Temp\\Radar\\" + fileName);
                }
            }
            if (!serviceFilePath.equals("")) {
                serviceFilePath = serviceUrl;
            }
            doppler.setJwImgPath(serviceFilePath);
        }
        // 拼接路径
        return resultList;
    }

    /*获取伊宁昭苏新源头10条雷达数据*/
    @RequestMapping("/getAllRadarInfo")
    @ResponseBody
    public Object getAllRadarInfo(HttpServletRequest request, Model model) throws ParseException, IOException {
        String stationId = request.getParameter("stationId");
        String type = "R20";
        String elevation = "0.5";
        RadarSearch dKey = new RadarSearch();
        dKey.setStationId(stationId);
        dKey.setType(type);
        if (!StringUtil.IsNullOrEmpty(elevation)) {
            dKey.setElevation(Float.parseFloat(elevation));
        }
        List<Doppler> resultList = qxInfoService.getNewRadarInfo(dKey);

        for (Doppler doppler : resultList) {
            String fileName = DbConfig.getRadarFileName(doppler.getType(), String.valueOf(doppler.getElevation()),
                    doppler.getStationId(), doppler.getDateChar(), doppler.getTimeChar()) + ".png";
            String serviceFilePath = "";
//            String path = request.getContextPath();
            String basePath =  "/Temp/radar/";
            String serviceUrl = basePath + fileName;
            String urlpath1 ;
            if (operatingSystem.equals("Windows")){
                urlpath1 = request.getSession().getServletContext().getRealPath("/") + "Temp\\radar\\";
            }else {
                urlpath1 = request.getSession().getServletContext().getRealPath("/") + "Temp/radar/";
            }

            serviceFilePath = urlpath1 + fileName;// 服务器文件
            FileUtil.mkDirs(urlpath1);// 创建文件夹，生成多级目录
            FileUtil.ClearTempFiles(urlpath1, 1000);// 清除缓存
            // 如果目录中不存在文件，下载雷达文件到temp目录
            File serviceFile = new File(serviceFilePath);// 服务器文件
            if (!serviceFile.exists()) {
                // 从mongdb获取图片
                Map<String, Object> map = new HashMap<String, Object>();
                map.put("dateyear", new DateTime(doppler.getDateChar()).toDateString().substring(0, 4));
                map.put("datechar", new DateTime(doppler.getDateChar()).toDateString());
                map.put("stationid", doppler.getStationId() == null ? doppler.getStationId() : doppler.getStationId().toString());
                String elev = doppler.getElevation().toString();
                // String elevsString = (doppler.getElevation() - (int) elev) == 0 ? String.valueOf((int) elev) : String.valueOf(doppler.getElevation());
                map.put("elevation", elev);
                map.put("ldtype", doppler.getType());
                map.put("timechar", doppler.getTimeChar() == null ? doppler.getTimeChar() : doppler.getTimeChar().toString());
                //map.put("type", "ld_png_file_m");
                map.put("collectionName", "ld_png_file");
                byte[] data = ms.selectData(map);
                if (data == null) {
                    serviceFilePath = "";
                } else {
                    FileUtil.bytesToFile(data, serviceFilePath);
//                    doppler.setJwImgPath("Temp\\Radar\\" + fileName);
                }
            }
            if (!serviceFilePath.equals("")) {
                serviceFilePath = serviceUrl;
            }
            doppler.setJwImgPath(serviceFilePath);
        }
        // 拼接路径
        return resultList;
    }
    @RequestMapping("/getNewRadarInfo")
    @ResponseBody
    public Object getNewRadarInfo(HttpServletRequest request, Model model) throws ParseException, IOException {

        String stationId = request.getParameter("stationId");
        String type = request.getParameter("type");

        switch (type) {
            case "基本反射率图19":
                type = "19";
                break;
            case "基本反射率图20":
                type = "R20";
                break;
            case "基本速度26":
                type = "26";
                break;
            case "基本速度27":
                type = "27";
                break;
            case "组合反射率图37":
                type = "CR37";
                break;
            case "组合反射率图38":
                type = "38";
                break;
            default:

                break;  // 确保这里有 break，防止误执行默认情况之外的代码
        }
        String elevation = request.getParameter("elevation");
        RadarSearch dKey = new RadarSearch();
        dKey.setStationId(stationId);
        dKey.setType(type);
        if (!StringUtil.IsNullOrEmpty(elevation)) {
            dKey.setElevation(Float.parseFloat(elevation));
        }
        List<Doppler> resultList = qxInfoService.getNewRadarInfo(dKey);

        for (Doppler doppler : resultList) {
            String fileName = DbConfig.getRadarFileName(doppler.getType(), String.valueOf(doppler.getElevation()),
                    doppler.getStationId(), doppler.getDateChar(), doppler.getTimeChar()) + ".png";
            String serviceFilePath = "";
//            String path = request.getContextPath();
            String basePath =  "/Temp/radar/";
            String serviceUrl = basePath + fileName;
            String urlpath1 ;
            if (operatingSystem.equals("Windows")){
                urlpath1 = request.getSession().getServletContext().getRealPath("/") + "Temp\\radar\\";
            }else {
                urlpath1 = request.getSession().getServletContext().getRealPath("/") + "Temp/radar/";
            }

            serviceFilePath = urlpath1 + fileName;// 服务器文件
            FileUtil.mkDirs(urlpath1);// 创建文件夹，生成多级目录
            FileUtil.ClearTempFiles(urlpath1, 1000);// 清除缓存
            // 如果目录中不存在文件，下载雷达文件到temp目录
            File serviceFile = new File(serviceFilePath);// 服务器文件
            if (!serviceFile.exists()) {
                // 从mongdb获取图片
                Map<String, Object> map = new HashMap<String, Object>();
                map.put("dateyear", new DateTime(doppler.getDateChar()).toDateString().substring(0, 4));
                map.put("datechar", new DateTime(doppler.getDateChar()).toDateString());
                map.put("stationid", doppler.getStationId() == null ? doppler.getStationId() : doppler.getStationId().toString());
                String elev = doppler.getElevation().toString();
                // String elevsString = (doppler.getElevation() - (int) elev) == 0 ? String.valueOf((int) elev) : String.valueOf(doppler.getElevation());
                map.put("elevation", elev);
                map.put("ldtype", doppler.getType());
                map.put("timechar", doppler.getTimeChar() == null ? doppler.getTimeChar() : doppler.getTimeChar().toString());
                //map.put("type", "ld_png_file_m");
                map.put("collectionName", "ld_png_file");
                byte[] data = ms.selectData(map);
                if (data == null) {
                    serviceFilePath = "";
                } else {
                    FileUtil.bytesToFile(data, serviceFilePath);
//                    doppler.setJwImgPath("Temp\\Radar\\" + fileName);
                }
            }
            if (!serviceFilePath.equals("")) {
                serviceFilePath = serviceUrl;
            }
            doppler.setJwImgPath(serviceFilePath);
        }
        // 拼接路径
        return resultList;
    }

    /**
     * 初始化云图界面
     * 2
     *
     * @return
     * @author dsq
     * @date 2018年7月9日
     */
    @RequestMapping("/initYtPage")
    @ResponseBody
    public Object initYtPage() throws ParseException {
        ArrayList<Object> arrayList = new ArrayList<Object>();
        String type = "FY";
        collectTime scaleNewDate = qxInfoService.getScaleNewDate(type);

        StringBuilder dateTime = new StringBuilder();
        dateTime.append(scaleNewDate.getYear() + "-");
        dateTime.append(scaleNewDate.getMonth() + "-");
        dateTime.append(scaleNewDate.getDay() + " ");
        dateTime.append(scaleNewDate.getHour());
        SimpleDateFormat sdf2 = new SimpleDateFormat("yyyy-MM-dd HH");
        Date d1 = sdf2.parse(dateTime.toString());
        // 加载列表
        DateTime date = new DateTime(d1);
        String startDate = date.AddDays(-1).toDateTimeString();
        String endDate = date.AddDays(1).toDateTimeString();
        arrayList.add(startDate);
        arrayList.add(endDate);
        String paramType = "云图配置";
        List<sys_config> sysConfig = configService.getSysConfig(paramType);
        List<String> sateKey2 = qxInfoService.getSateTypes();
        arrayList.add(sysConfig);
        arrayList.add(sateKey2);
        return arrayList;
    }


    /*获取大屏左侧搜索最新10条云图*/
    @RequestMapping("/get10YtInfo")
    @ResponseBody
    public Object get10YtInfo(HttpServletRequest request, Model model) throws ParseException {
        String type = request.getParameter("type");
        SateSearch sateKey = new SateSearch();
        sateKey.setType(type);
        List<SatelliteNephoram> resultList = qxInfoService.getYtInfo(sateKey);
        String urlpath ;
        if (operatingSystem.equals("Windows")){
            urlpath = request.getSession().getServletContext().getRealPath("/") + "Temp\\yt\\";
        }else {
            urlpath = request.getSession().getServletContext().getRealPath("/") + "Temp/yt/";
        }

        FileUtil.mkDirs(urlpath);// 创建文件夹
        // 当图片达到1000张时清除
        FileUtil.ClearTempFiles(urlpath, 1000);
        for (SatelliteNephoram sate : resultList) {
            String fileName = DbConfig.getYtFileName(sate.getType(), sate.getDateChar(), sate.getTimeChar()) + ".png";
            String servicePath = urlpath + fileName;
            File serviceFile = new File(servicePath);

            if (serviceFile.exists()) {
                sate.setLbImgPath("Temp\\yt\\" + fileName);
            } else {
                // 从mongdb获取图片
                Map<String, Object> map = new HashMap<String, Object>();
                map.put("dateyear", new DateTime(sate.getDateChar()).toDateString().substring(0, 4));
                map.put("datechar", new DateTime(sate.getDateChar()).toDateString());
                map.put("yttype", sate.getType());
                map.put("timechar", sate.getTimeChar());
                // map.put("type", "yt_png_file_m");
                map.put("collectionName", "yt_png_file");
                byte[] data = ms.selectData(map);
                String dataS = "";
                if (data == null) {
                    dataS = "";
                } else {
                    dataS = new String(data);
                }
                if (dataS.equals("")) {
                    sate.setLbImgPath("");
                } else {
                    FileUtil.bytesToFile(data, servicePath);
                    sate.setLbImgPath("Temp\\yt\\" + fileName);
                }
            }
        }
        // 拼接路径
        return resultList;
    }

    /**
     * 获取云图信息
     * 2
     *
     * @param request
     * @param model
     * @return
     * @throws ParseException
     * @author dsq
     * @date 2018年7月9日
     */
    @RequestMapping("/getYtInfo")
    @ResponseBody
    public Object getYtInfo(HttpServletRequest request, Model model) throws ParseException {
        String startDate = request.getParameter("startDate");
        String endDate = request.getParameter("endDate");
        String type = request.getParameter("type");
        SateSearch sateKey = new SateSearch();
        sateKey.setStartDate(DateTime.parseDateTime(startDate).toDateTimeString());
        sateKey.setEndDate(DateTime.parseDateTime(endDate).toDateTimeString());
        sateKey.setType(type);
        List<SatelliteNephoram> resultList = qxInfoService.getSateInfo(sateKey);
        String urlpath ;
        if (operatingSystem.equals("Windows")){
             urlpath = request.getSession().getServletContext().getRealPath("/") + "Temp\\yt\\";
        }else {
             urlpath = request.getSession().getServletContext().getRealPath("/") + "Temp/yt/";
        }

        FileUtil.mkDirs(urlpath);// 创建文件夹
        // 当图片达到1000张时清除
        FileUtil.ClearTempFiles(urlpath, 1000);
        for (SatelliteNephoram sate : resultList) {
            String fileName = DbConfig.getYtFileName(sate.getType(), sate.getDateChar(), sate.getTimeChar()) + ".png";
            String servicePath = urlpath + fileName;
            File serviceFile = new File(servicePath);

            if (serviceFile.exists()) {
                sate.setLbImgPath("Temp\\yt\\" + fileName);
            } else {
                // 从mongdb获取图片
                Map<String, Object> map = new HashMap<String, Object>();
                map.put("dateyear", new DateTime(sate.getDateChar()).toDateString().substring(0, 4));
                map.put("datechar", new DateTime(sate.getDateChar()).toDateString());
                map.put("yttype", sate.getType());
                map.put("timechar", sate.getTimeChar());
                // map.put("type", "yt_png_file_m");
                map.put("collectionName", "yt_png_file");
                byte[] data = ms.selectData(map);
                String dataS = "";
                if (data == null) {
                    dataS = "";
                } else {
                    dataS = new String(data);
                }
                if (dataS.equals("")) {
                    sate.setLbImgPath("");
                } else {
                    FileUtil.bytesToFile(data, servicePath);
                    sate.setLbImgPath("Temp\\yt\\" + fileName);
                }
            }
        }
        // 拼接路径
        return resultList;
    }

    /**
     * app 云图查询二维
     *
     * @param request
     * @param model
     * @return
     * @throws ParseException
     */
    @RequestMapping("/getYtInfo1")
    @ResponseBody
    public Object getYtInfo1(HttpServletRequest request, Model model) throws ParseException {
        String startDate = request.getParameter("startDate");
        String endDate = request.getParameter("endDate");
        String type = request.getParameter("type");
        SateSearch sateKey = new SateSearch();
        sateKey.setStartDate(DateTime.parseDateTime(startDate).toDateTimeString());
        sateKey.setEndDate(DateTime.parseDateTime(endDate).toDateTimeString());
        sateKey.setType(type);
        List<SatelliteNephoram> resultList = qxInfoService.getSateInfo(sateKey);
        String urlpath ;
        if (operatingSystem.equals("Windows")){
            urlpath = request.getSession().getServletContext().getRealPath("/") + "Temp\\yt\\";// 临时文件目录
        }else {
            urlpath = request.getSession().getServletContext().getRealPath("/") + "Temp/yt/";// 临时文件目录
        }

        FileUtil.mkDirs(urlpath);// 创建文件夹
        // 当图片达到1000张时清除
        FileUtil.ClearTempFiles(urlpath, 1000);
        for (SatelliteNephoram sate : resultList) {
            String fileName = DbConfig.getYtFileName(sate.getType(), sate.getDateChar(), sate.getTimeChar()) + ".png";
            String servicePath = urlpath + fileName;
            File serviceFile = new File(servicePath);

            if (serviceFile.exists()) {
                sate.setLbImgPath("Temp\\yt\\" + fileName);
            } else {
                // 从mongdb获取图片
                Map<String, Object> map = new HashMap<String, Object>();
                map.put("dateyear", new DateTime(sate.getDateChar()).toDateString().substring(0, 4));
                map.put("datechar", new DateTime(sate.getDateChar()).toDateString());
                map.put("yttype", sate.getType());
                map.put("timechar", sate.getTimeChar());
                map.put("collectionName", "yt_png_file");
                byte[] data = ms.selectData(map);
                String dataS = "";
                if (data == null) {
                    dataS = "";
                } else {
                    dataS = new String(data);
                }
                if (dataS.equals("")) {
                    sate.setLbImgPath("");
                } else {
                    FileUtil.bytesToFile(data, servicePath);
                    sate.setLbImgPath("Temp\\yt\\" + fileName);
                }
            }
        }
        // 拼接路径
        return resultList;
    }
    /*
    * 获取城市站点*/
    @RequestMapping("/getCity")
    @ResponseBody
    public Object getCity() {
        Object city = configService.getCity();
        if (city != null){
            return  city;
        }else {
            return "暂无数据";
        }

    }

    /*
    *
    * 决策服务产品*/
    @RequestMapping("/getDecision")
    @ResponseBody
    public Object getDecision(String advcode ) {
        String producttype = "";
        if (advcode.equals(DbConfig.advCode)){
            producttype = "市级";
        }else {
            producttype = "县级";
        }
        Object decision = configService.getDecision(producttype);
        if (decision != null){
            return decision;
        }else{
            return "暂无数据";
        }

    }

    /*
     *
     * 天气快报等接口*/
    @RequestMapping("/getNewDecision")
    @ResponseBody
    public Object getNewDecision(HttpServletRequest request, Model model) {
        try {
            StringBuilder sql1 = new StringBuilder();
            sql1.append("SELECT id,productname,producttype2,maketime ")
                    .append("FROM summary_product ")
                    .append("WHERE (producttype2, maketime) IN (\n" +
                            "    SELECT producttype2, MAX(maketime)\n" +
                            "    FROM summary_product\n" +
                            "    WHERE producttype = '市级'\n" +
                            "    GROUP BY producttype2\n" +
                            ") ")
                    .append("ORDER BY maketime DESC");

            List<Map<String, Object>> hourInfo = comDisplayService.getNewDecision(sql1.toString());


            return Results.success("获取天气快报文档数据", 1, hourInfo);
        }  catch (Exception e){
            return Results.fail(e.getMessage());
        }
    }
    /**
     * 初始化雨情
     * 2
     *
     * @return
     */
    @RequestMapping("/initScalePage")
    @ResponseBody
    public Object initScalePage() throws ParseException {
        ArrayList<Object> resultList = new ArrayList<Object>();
        // 时间
        String type = "SmallScale";
        collectTime scaleNewDate = qxInfoService.getScaleNewDate(type);// 已修改
        StringBuilder dateTime = new StringBuilder();
        dateTime.append(scaleNewDate.getYear() + "-");
        dateTime.append(scaleNewDate.getMonth() + "-");
        dateTime.append(scaleNewDate.getDay() + " ");
        dateTime.append(scaleNewDate.getHour());

        SimpleDateFormat sdf2 = new SimpleDateFormat("yyyy-MM-dd HH");
        Date d1 = sdf2.parse(dateTime.toString());
        // 加载列表
        DateTime date = new DateTime(d1);
        resultList.add(dateTime.toString());
        List<adminCode> countyList = configService.getTown();

        List<EasyuiTree> easyuiTrees = new ArrayList<EasyuiTree>();
        for (int i = 0; i < countyList.size(); i++) {
            EasyuiTree tree = new EasyuiTree();
            tree.setId(i + 1);
            tree.setChecked(true);
            tree.setText(countyList.get(i).getAdvname().trim());
            tree.setValue(countyList.get(i).getAdvcode().trim());
            easyuiTrees.add(tree);
        }
        //雨情
        List<WaterStation> ylzList = configService.getRainSta();//
        List<EasyuiTree> ylzeasyuiTrees = new ArrayList<EasyuiTree>();
        for (int i = 0; i < ylzList.size(); i++) {
            EasyuiTree tree1 = new EasyuiTree();
            tree1.setId(i + 1);
            tree1.setValue(ylzList.get(i).getStcd().trim());
            tree1.setChecked(true);
            tree1.setText(ylzList.get(i).getStnm().trim());
            ylzeasyuiTrees.add(tree1);

        }

        resultList.add(easyuiTrees);
        resultList.add(ylzeasyuiTrees);
        return resultList;
    }

    /**
     * 蒸发量页面初始化
     *
     * @return
     */
    @RequestMapping("/iniEvaportranspirationPage")
    @ResponseBody
    public Object initEvaportranspirationPage() {
        ArrayList<Object> resultList = new ArrayList<Object>();
        // 时间
        DateTime endTime = new DateTime(qxInfoService.getScaleDate());// 已修改
        resultList.add(endTime.toDateTimeString());
        //乡镇
        List<SmallScaleStation> countyList = configService.getStion();//
        List<EasyuiTree> easyuiTrees = new ArrayList<EasyuiTree>();
        for (int i = 0; i < countyList.size(); i++) {
            EasyuiTree tree = new EasyuiTree();
            tree.setId(i + 1);
            tree.setChecked(true);
            tree.setText(countyList.get(i).getStationName().trim());
            easyuiTrees.add(tree);
        }
        resultList.add(easyuiTrees);
        return resultList;
    }
/*大屏-实况信息*/
    @RequestMapping("/nowInfo")
    @ResponseBody
    public Object  nowInfo(HttpServletRequest request, Model model) throws ParseException, IOException {
        String county = request.getParameter("advname");
        //String stationId = configService.getStationId(county);
        String stationId = "";
        switch (county){
            case "伊犁州直":
                stationId = "51431";
                break;
            case "伊犁河谷":
                stationId = "51431";
                break;
            case "伊宁市":
                stationId = "51431";
                break;
            case "奎屯市":
                stationId = "Y6566";
                break;
            case "霍尔果斯市":
                stationId = "51328";
                break;
            case "察县":
                stationId = "51430";
                break;
            case "伊宁县":
                stationId = "51434";
                break;
            case "巩留县":
                stationId = "51435";
                break;
            case "霍城县":
                stationId = "51329";
                break;
            case "新源县":
                stationId = "51436";
                break;
            case "昭苏县":
                stationId = "51437";
                break;
            case "特克斯县":
                stationId = "51438";
                break;
            case "尼勒克县":
                stationId = "51433";
                break;
            default:
                return null;
        }

        StringBuilder sql3 = new StringBuilder();
        List<Map<String, Object>> res2 = new ArrayList<>();
        sql3.append("select datetime ")
                .append("from msg_other_minute ")
                .append("ORDER BY datetime DESC LIMIT 1 ");
        try {
            res2 = comDisplayService.getNewShiJian(sql3.toString());
        } catch (Exception e) {
            throw new RuntimeException(e);
        }
        String datetime = res2.get(0).get("datetime").toString();
        // 获取当前时间
        Date date = new Date();
        // 获取当前时间的 "yyyy-MM-dd HH" 格式
        SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");

// 获取当前时间，减去24小时
        Calendar calendar = Calendar.getInstance();
        calendar.setTime(date);
        calendar.add(Calendar.HOUR_OF_DAY, -24); // 将时间减去24小时

// 将分钟和秒设置为0
        calendar.set(Calendar.MINUTE, 0);
        calendar.set(Calendar.SECOND, 0);
        calendar.set(Calendar.MILLISECOND, 0); // 如果需要的话，也可以将毫秒设置为0
// 获取调整后的时间并格式化为字符串
        String startTime = simpleDateFormat.format(calendar.getTime());
        calendar.setTime(date);
        calendar.add(Calendar.HOUR_OF_DAY, -1); // 将时间减去1小时

// 将分钟和秒设置为0
        calendar.set(Calendar.MINUTE, 0);
        calendar.set(Calendar.SECOND, 0);
        calendar.set(Calendar.MILLISECOND, 0); // 如果需要的话，也可以将毫秒设置为0
// 获取调整后的时间并格式化为字符串
        String startTime1 = simpleDateFormat.format(calendar.getTime());
        // 设置结束时间的分钟、秒和毫秒为0
        calendar.setTime(date);
        calendar.set(Calendar.MINUTE, 0);
        calendar.set(Calendar.SECOND, 0);
        calendar.set(Calendar.MILLISECOND, 0); // 也将毫秒设置为0
        String endTime = simpleDateFormat.format(calendar.getTime());

        StringBuilder sql = new StringBuilder();
        sql.append("select tem,win_s_avg_2mi,win_s_avg_10mi,vis_hor_1mi ")
                .append(" from msg_other_minute ")
                .append("where datetime = '"+datetime+"'" )
                .append("AND station_id_c = '"+stationId+"'");
        StringBuilder sql1 = new StringBuilder();
        sql1.append("select SUM(pre) AS value ")
                .append(" from msg_rain_minute ")
                .append("where datetime >= '"+startTime1+"'" )
                .append("AND datetime <= '"+endTime+"'" )
                .append("AND station_id_c = '"+stationId+"'");
        StringBuilder sql2 = new StringBuilder();
        sql2.append("select SUM(pre) AS value ")
                .append(" from msg_rain_minute ")
                .append("where datetime >= '"+startTime+"'" )
                .append("AND datetime <= '"+endTime+"'" )
                .append("AND station_id_c = '"+stationId+"'");
        Map<String, Object> nowDate = null;
        Map<String, Object> nowDate1 = null;
        Map<String, Object> nowDate2 = null;
        try {
            nowDate = configService.getNowDate(sql.toString());
            nowDate1 = configService.getNowDate1(sql1.toString());
            nowDate2 = configService.getNowDate2(sql2.toString());
        } catch (Exception e) {
            throw new RuntimeException(e);
        }
        //HashMap nowDate = configService.getNowDate(datetime, stationId);
        //HashMap nowDate1 = configService.getNowDate1(startTime, endTime, stationId);
        HashMap<String, Object> map = new HashMap<>();
        if (nowDate.size() == 0){
            map.put("temp", 0.0);
            map.put("bestWind", 0.0);
            map.put("maxWind", 0.0);
            map.put("oneVis", 0.0);
            map.putAll(nowDate1);
            map.putAll(nowDate2);
        }else {
            map.putAll(nowDate);
            map.putAll(nowDate1);
            map.putAll(nowDate2);
        }
        return  map;

    }

    @RequestMapping("/elementQuery")
    @ResponseBody
    public Object  elementQuery(HttpServletRequest request, Model model) throws ParseException, IOException {
        String strStartDate = request.getParameter("startDate");
        String strEndDate = request.getParameter("endDate");
        String strCountys = request.getParameter("countys");
        String type = request.getParameter("type");
        String element = request.getParameter("element");
        String elemType = request.getParameter("text");
        String equMap = request.getParameter("equMap");
        final String etype = elemType;
        List<Object> result = new ArrayList<>();
        //根据参数生成唯一MD5编码
        String rainSearchId = MD5Utils.MD5Encode(strStartDate + strEndDate + strCountys + type + element + elemType, "utf-8");
        if (rainSearchId.equals(request.getSession().getAttribute("rainSearchId"))) {
            //已经进行过缓存了,直接读取缓存内容，没有缓存则进行查询
            result = (ArrayList) request.getSession().getAttribute("rainSearchData");
        } else {
            request.getSession().setAttribute("elemType", elemType);
            request.getSession().setAttribute("element", element);
            request.getSession().setAttribute("rainSearchId", rainSearchId);
            String[] countys = strCountys.split(",");
            Date startDate = DateTime.parseDateTime(strStartDate).toDate();
            Date endDate = DateTime.parseDateTime(strEndDate).toDate();
            if (elemType.equals("整点雨量")) {
                elemType = "1小时雨量";
            }
            if (elemType.equals("累积雨量")) {
                elemType = "雨量";
            }
            if (elemType.contains("温度")) {
                elemType = "温度";
            }
            if (elemType.contains("湿度")) {
                elemType = "湿度";
            }
            if (elemType.contains("风")) {
                elemType = "风速";
            }
            if (elemType.contains("气压")) {
                elemType = "气压";
            }
            if (elemType.contains("能见度")) {
                elemType = "能见度";
            }
            ActualElemQuery elemQuery = new ActualElemQuery();
            elemQuery.setCountys(Arrays.asList(countys));
            elemQuery.setElement(element);
            elemQuery.setStartDate(startDate);
            elemQuery.setEndDate(endDate);
            elemQuery.setType(type);
           List<ActualData> resultList = skInfoService.qxElementQuery(elemQuery);
            List<ElemContourSet> contourSet = configService.getElemContourSet(elemType);

            String txtPath = "";
            if (!elemType.contains("能见度")) {
                //生成等值图
                if (equMap.equals("true")) {
                    Thread t = null;
                    List<ActualData> finalResultList = resultList;
                    txtPath = webRootKey1(finalResultList, contourSet, etype, request);
                }
                result.add(classifyElemByValue(resultList, contourSet, elemType));
                result.add(contourSet);
                String uniqueno = "";
                String posurl = "";
                if (!StringUtil.IsNullOrEmpty(txtPath)) {
                    //服务器地址
//                    DmServiceConnector conn = new DmServiceConnector("localhost", "6163");//改成181地址
                    if (conn != null) {
                        uniqueno = conn.getCallPlugin("ContourService.InterpolationService", "GetInterpolationWork",
                                txtPath);
//                        posurl = conn.getCallPlugin("ContourService.InterpolationService", "GetPosFile", uniqueno + "|" + DbConfig.TAB + "", "");
                    } else {
                        DmServiceConnector conn = new DmServiceConnector("127.0.0.1", "6163");
                        uniqueno = conn.getCallPlugin("ContourService.InterpolationService", "GetInterpolationWork",
                                txtPath);
//                        posurl = conn.getCallPlugin("ContourService.InterpolationService", "GetPosFile", uniqueno + "|" + DbConfig.TAB + "", "");
                    }
                    result.add(uniqueno);
//                    result.add(getPos(posurl));
                }
            } else result.add("");

            String RainDisp = "";
            double Total = 0.0;
            int noRain = 0;
            int littleRain = 0;
            int middleRain = 0;
            int bigRain = 0;
            int hervyRain = 0;
            int hardRain = 0;
            int veryHardRain = 0;

            for (int i = 0; i < resultList.size(); i++) {
                double rain = resultList.get(i).getRain();
                if (rain >= 200) {
                    veryHardRain++;
                } else if (rain >= 100) {
                    hardRain++;

                } else if (rain >= 50) {
                    hervyRain++;
                } else if (rain >= 25) {
                    bigRain++;
                } else if (rain >= 10) {
                    middleRain++;
                } else if (rain > 0) {
                    littleRain++;
                } else {
                    noRain++;
                }

            }
            if (veryHardRain != 0) {
                if (!strStartDate.equals(strEndDate)) {
                    RainDisp = String.format("根据监测显示，时间:%s时至%s时,据全市%s个区域自动气象站资料统计，有%s站小雨，%s站中雨，%s站大雨，%s站暴雨,%s站大暴雨，%s站特大暴雨。其中最大降雨量为%smm(%s)", strStartDate, strEndDate, resultList.size(), littleRain, middleRain, bigRain, hervyRain, hardRain, veryHardRain, resultList.get(0).getRain(), resultList.get(0).getStationName());

                } else {
                    RainDisp = String.format("根据监测显示，时间:%s时,据全市%s个区域自动气象站资料统计，有%s站小雨，%s站中雨，%s站大雨，%s站暴雨,%s站大暴雨，%s站特大暴雨。其中最大降雨量为%smm(%s)", strStartDate, resultList.size(), littleRain, middleRain, bigRain, hervyRain, hardRain, veryHardRain, resultList.get(0).getRain(), resultList.get(0).getStationName());

                }

            } else if (hardRain != 0) {
                if (!strStartDate.equals(strEndDate)) {
                    RainDisp = String.format("根据监测显示，时间:%s时至%s时,据全市%s个区域自动气象站资料统计，有%s站小雨，%s站中雨，%s站大雨，%s站暴雨,%s站大暴雨。其中最大降雨量为%smm(%s)", strStartDate, strEndDate, resultList.size(), littleRain, middleRain, bigRain, hervyRain, hardRain, resultList.get(0).getRain(), resultList.get(0).getStationName());

                } else {
                    RainDisp = String.format("根据监测显示，时间:%s时,据全市%s个区域自动气象站资料统计，有%s站小雨，%s站中雨，%s站大雨，%s站暴雨,%s站大暴雨。其中最大降雨量为%smm(%s)", strStartDate, resultList.size(), littleRain, middleRain, bigRain, hervyRain, hardRain, resultList.get(0).getRain(), resultList.get(0).getStationName());
                }
            } else if (hervyRain != 0) {
                if (!strStartDate.equals(strEndDate)) {
                    RainDisp = String.format("根据监测显示，时间:%s时至%s时,据全市%s个区域自动气象站资料统计，有%s站小雨，%s站中雨，%s站大雨，%s站暴雨。其中最大降雨量为%smm(%s)", strStartDate, strEndDate, resultList.size(), littleRain, middleRain, bigRain, hervyRain, resultList.get(0).getRain(), resultList.get(0).getStationName());

                } else {
                    RainDisp = String.format("根据监测显示，时间:%s时,据全市%s个区域自动气象站资料统计，有%s站小雨，%s站中雨，%s站大雨，%s站暴雨。其中最大降雨量为%smm(%s)", strStartDate, resultList.size(), littleRain, middleRain, bigRain, hervyRain, resultList.get(0).getRain(), resultList.get(0).getStationName());

                }
            } else if (bigRain != 0) {
                if (!strStartDate.equals(strEndDate)) {
                    RainDisp = String.format("根据监测显示，时间:%s时至%s时,据全市%s个区域自动气象站资料统计，有%s站小雨，%s站中雨，%s站大雨。其中最大降雨量为%smm(%s)", strStartDate, strEndDate, resultList.size(), littleRain, middleRain, bigRain, resultList.get(0).getRain(), resultList.get(0).getStationName());

                } else {
                    RainDisp = String.format("根据监测显示，时间:%s时,据全市%s个区域自动气象站资料统计，有%s站小雨，%s站中雨，%s站大雨。其中最大降雨量为%smm(%s)", strStartDate, resultList.size(), littleRain, middleRain, bigRain, resultList.get(0).getRain(), resultList.get(0).getStationName());
                }
            } else if (middleRain != 0) {
                if (!strStartDate.equals(strEndDate)) {
                    RainDisp = String.format("根据监测显示，时间:%s时至%s时,据全市%s个区域自动气象站资料统计，有%s站小雨，%s站中雨。其中最大降雨量为%smm(%s)", strStartDate, strEndDate, resultList.size(), littleRain, middleRain, resultList.get(0).getRain(), resultList.get(0).getStationName());

                } else {
                    RainDisp = String.format("根据监测显示，时间:%s时,据全市%s个区域自动气象站资料统计，有%s站小雨，%s站中雨。其中最大降雨量为%smm(%s)", strStartDate, resultList.size(), littleRain, middleRain, resultList.get(0).getRain(), resultList.get(0).getStationName());

                }
            } else if (littleRain != 0) {
                if (!strStartDate.equals(strEndDate)) {
                    RainDisp = String.format("根据监测显示，时间:%s时至%s时,据全市%s个区域自动气象站资料统计，有%s站小雨。其中最大降雨量为%smm(%s)", strStartDate, strEndDate, resultList.size(), littleRain, resultList.get(0).getRain(), resultList.get(0).getStationName());

                } else {
                    RainDisp = String.format("根据监测显示，时间:%s时,据全市%s个区域自动气象站资料统计，有%s站小雨。其中最大降雨量为%smm(%s)", strStartDate, resultList.size(), littleRain, resultList.get(0).getRain(), resultList.get(0).getStationName());

                }
            } else {
                if (!strStartDate.equals(strEndDate)) {
                    RainDisp = String.format("根据监测显示，时间:%s时至%s时,据全市%s个区域自动气象站资料统计，有%s站无雨。", strStartDate, strEndDate, resultList.size(), noRain);
                } else {
                    RainDisp = String.format("根据监测显示，时间:%s时,据全市%s个区域自动气象站资料统计，有%s站无雨。", strStartDate, resultList.size(), noRain);
                }
            }
            result.add(RainDisp);
            request.getSession().setAttribute("rainSearchData", result);

        }

        return result;
    }

    /**
     * 气象要素查询
     * 2
     *
     * @param request
     * @param model
     * @return
     * @throws ParseException
     * @author dsq
     * @date 2018年7月11日
     */
    @RequestMapping("/rainQuery")
    @ResponseBody
    public Object rainQuery(HttpServletRequest request, Model model) throws ParseException, IOException {
        // water_station sttp PPMM
        List<Object> result = new ArrayList<>();
        String strStartDate = request.getParameter("startDate");
        String strEndDate = request.getParameter("endDate");
        String strCountys = request.getParameter("countys");
        String type = request.getParameter("type");
        String element = request.getParameter("element");
        String equMap = request.getParameter("equMap");
        //阈值
        String rainFilter = request.getParameter("yz");
        String elemType = request.getParameter("text");
        //0/1
        String valley = request.getParameter("valley");
//        String ylzs = request.getParameter("ylzs");
        String qxstation = request.getParameter("qxstation");
        String swstation = request.getParameter("swstation");
        List<WeatherVo> weatherByCondition = new ArrayList<>();
        //获取前台传过来的编号(选择的气象站编号)
        List<String> countys = Arrays.asList(strCountys.split(","));
        if (!StringUtil.IsNullOrEmpty(swstation) && swstation.equals("1")) {
            weatherByCondition = qxInfoService.getWeatherByCondition(countys, strStartDate, strEndDate);
        }
        String coordinate = "";
        if (valley != null) {//valley != "" && !valley.equals("") &&
            final String etype = elemType;
            //根据参数生成唯一MD5编码
            String rainSearchId = MD5Utils.MD5Encode(strStartDate + strEndDate + strCountys + type + element + elemType + valley, "utf-8");
            if (rainSearchId.equals(request.getSession().getAttribute("rainQueryId"))) {
                //已经进行过缓存了,直接读取缓存内容，没有缓存则进行查询
                result = (ArrayList) request.getSession().getAttribute("rainQueryData");
            } else {
                List<river_basin> getvalley = configService.Getvalley(valley);
                List<DmMapPoint> lonlat = new ArrayList<DmMapPoint>();
                List<String> stationids = new ArrayList<String>();
                String skstations = "";


                if (getvalley.size() > 0) {
                    for (river_basin r : getvalley) {
                        coordinate = r.getCoordinate();
                    }
                    String[] posArr = coordinate.split("\\*");// 三个部分，*分隔
                    for (String pos : posArr) {
                        try {
                            if (pos == null || pos.equals("")) {
                                continue;
                            }
                            String[] dotset = pos.split(";");// 坐标数组
                            DmMapPoint[] points = new DmMapPoint[dotset.length];
                            DmMapPoint[] point = new DmMapPoint[dotset.length];
                            Integer index = 0;
                            for (String strDot : dotset) {
                                String[] dot = strDot.split(",");
                                points[index] = new DmMapPoint(Double.parseDouble(dot[0]), Double.parseDouble(dot[1]));
                                point[index] = transformService.LambertConvertToLonLat(Double.parseDouble(dot[0]), Double.parseDouble(dot[1]));
                                index++;
                            }
                            MapCommon dmMapCom = new MapCommon();
                            int[] parts = new int[1];
                            parts[0] = points.length;
                            DmMapRectangle rect = dmMapCom.getRectMinMax(Arrays.asList(point));
                            DmMapPoint dmDotLb1 = new DmMapPoint(rect.minX, rect.minY);
                            DmMapPoint dmDotLb2 = new DmMapPoint(rect.maxX, rect.maxY);
                            rect.minX = dmDotLb1.x;
                            rect.minY = dmDotLb1.y;
                            rect.maxX = dmDotLb2.x;
                            rect.maxY = dmDotLb2.y;
                            List<smallscale_station> stations = qxInfoService.getStations(rect);

                            for (smallscale_station city : stations) {
                                DmMapPoint dmDotJW = new DmMapPoint(city.getLongitude(), city.getLatitude());
                                DmMapPoint dmDotLb = new DmMapPoint(dmDotJW.x, dmDotJW.y);
                                if (dmMapCom.pointWithinPolygon(Arrays.asList(points), dmDotLb.x, dmDotLb.y)) {
                                    if (!skstations.contains(city.getStationid())) {
                                        skstations += city.getStationid() + ",";
                                        lonlat.add(dmDotJW);
                                        stationids.add(city.getStationid());
                                    }
                                }
                            }
                        } catch (Exception e) {
                            System.err.println(e.getStackTrace());
                        }
                    }
                }
                String[] split = skstations.split(",");
                request.getSession().setAttribute("elemType", elemType);
                request.getSession().setAttribute("element", element);
                request.getSession().setAttribute("rainQueryId", rainSearchId);
                Date startDate = DateTime.parseDateTime(strStartDate, "yyyy-MM-dd HH").toDate();
                Date endDate = DateTime.parseDateTime(strEndDate, "yyyy-MM-dd HH").toDate();
                if (elemType.equals("整点雨量")) {
                    elemType = "1小时雨量";
                }
                if (elemType.equals("预报雨量")) {
                    elemType = "1小时雨量";
                }
                if (elemType.equals("累积雨量")) {
                    elemType = "雨量";
                }
                ActualElemQuery elemQuery = new ActualElemQuery();
                elemQuery.setCountys(countys);
                elemQuery.setElement(element);
                elemQuery.setStartDate(startDate);
                elemQuery.setEndDate(endDate);
                elemQuery.setType(type);
                elemQuery.setRainFilter(rainFilter);
                if (split.length > 0) {
                    elemQuery.setStations(Arrays.asList(split));
                }
                List<ActualData> resultList = new ArrayList<>();
                //判断气象站
                if (!StringUtil.IsNullOrEmpty(qxstation) && qxstation.equals("1")) {
                    List<ActualData> qxResultList = skInfoService.qxElementQuery(elemQuery);
                    if (qxResultList != null && qxResultList.size() > 0) {
                        //阈值判断
                        if(!StringUtil.IsNullOrEmpty(rainFilter)){
                        for (ActualData actualData : qxResultList) {
                            if(actualData.getRain()>=Double.parseDouble(rainFilter)){
                                resultList.add(actualData);
                            }
                        }
                        }else {
                        resultList = qxResultList;
                        }
                    }
                }

                if (weatherByCondition != null && resultList != null) {
                    if(!StringUtil.IsNullOrEmpty(rainFilter)){
                    for (WeatherVo weatherVo : weatherByCondition) {
                        if (Double.parseDouble(weatherVo.getRain()) >= Double.parseDouble(rainFilter)) {
                            ActualData actualData = new ActualData();
                            actualData.setLat(Double.valueOf(weatherVo.getLat()));
                            actualData.setLon(Double.valueOf(weatherVo.getLon()));
                            actualData.setRain(weatherVo.getRain() != null ? Double.valueOf(weatherVo.getRain()) : 0.0);
                            actualData.setStationId(weatherVo.getStationid());
                            actualData.setCounty(weatherVo.getAddvcd());
                            actualData.setStationName(weatherVo.getStationname());
                            resultList.add(actualData);
                        }
                    }
                    }else {
                        for (WeatherVo weatherVo : weatherByCondition) {
                            ActualData actualData = new ActualData();
                            actualData.setLat(Double.valueOf(weatherVo.getLat()));
                            actualData.setLon(Double.valueOf(weatherVo.getLon()));
                            actualData.setRain(weatherVo.getRain() != null ? Double.valueOf(weatherVo.getRain()) : 0.0);
                            actualData.setStationId(weatherVo.getStationid());
                            actualData.setCounty(weatherVo.getAddvcd());
                            actualData.setStationName(weatherVo.getStationname());
                            resultList.add(actualData);
                        }
                    }
                }

                List<ElemContourSet> contourSet = configService.getElemContourSet(elemType);
                //存放等值图地址
                String txtPath = "";
                //存放等值图地址
                if (!elemType.contains("能见度")) {
                    //生成等值图
                    if (equMap.equals("true")) {
                        Thread t = null;
                        List<ActualData> finalResultList = resultList;
                        txtPath = webRootKey2(finalResultList, contourSet, etype, request);
                    }
                    result.add(classifyElemByValue(resultList, contourSet, elemType));
                    result.add(contourSet);
                    String uniqueno = "";
                    if (!StringUtil.IsNullOrEmpty(txtPath)) {
                        //服务器地址
//                        DmServiceConnector conn = new DmServiceConnector("localhost", "6163");//改成181地址
                        if (conn != null) {
                            uniqueno = conn.getCallPlugin("ContourService.InterpolationService", "GetInterpolationWork",
                                    txtPath);
                        } else {
                            DmServiceConnector conn = new DmServiceConnector("localhost", "6163");
                            uniqueno = conn.getCallPlugin("ContourService.InterpolationService", "GetInterpolationWork",
                                    txtPath);
                        }
                        result.add(uniqueno);
                    }
                } else result.add("");

                String RainDisp = "";
                double Total = 0.0;
                double noRain = 0.0;
                int littleRain = 0;
                int middleRain = 0;
                int bigRain = 0;
                int hervyRain = 0;
                int hardRain = 0;
                int veryHardRain = 0;

                for (int i = 0; i < resultList.size(); i++) {
                    double rain = resultList.get(i).getRain();
                    if (rain >= 200) {
                        veryHardRain++;
                    } else if (rain >= 100) {
                        hardRain++;

                    } else if (rain >= 50) {
                        hervyRain++;
                    } else if (rain >= 25) {
                        bigRain++;
                    } else if (rain >= 10) {
                        middleRain++;
                    } else if (rain > 0) {
                        littleRain++;
                    } else {
                        noRain++;
                    }

                }
                if (veryHardRain != 0) {
                    if (!strStartDate.equals(strEndDate)) {
                        RainDisp = String.format("根据监测显示，时间:%s时至%s时,据全市%s个区域自动气象站资料统计，有%s站小雨，%s站中雨，%s站大雨，%s站暴雨,%s站大暴雨，%s站特大暴雨。其中最大降雨量为%smm(%s)", strStartDate, strEndDate, resultList.size(), littleRain, middleRain, bigRain, hervyRain, hardRain, veryHardRain, resultList.get(0).getRain(), resultList.get(0).getStationName());
                    } else {
                        RainDisp = String.format("根据监测显示，时间:%s时,据全市%s个区域自动气象站资料统计，有%s站小雨，%s站中雨，%s站大雨，%s站暴雨,%s站大暴雨，%s站特大暴雨。其中最大降雨量为%smm(%s)", strStartDate, resultList.size(), littleRain, middleRain, bigRain, hervyRain, hardRain, veryHardRain, resultList.get(0).getRain(), resultList.get(0).getStationName());

                    }
                } else if (hardRain != 0) {
                    if (!strStartDate.equals(strEndDate)) {
                        RainDisp = String.format("根据监测显示，时间:%s时至%s时,据全市%s个区域自动气象站资料统计，有%s站小雨，%s站中雨，%s站大雨，%s站暴雨,%s站大暴雨。其中最大降雨量为%smm(%s)", strStartDate, strEndDate, resultList.size(), littleRain, middleRain, bigRain, hervyRain, hardRain, resultList.get(0).getRain(), resultList.get(0).getStationName());

                    } else {
                        RainDisp = String.format("根据监测显示，时间:%s时,据全市%s个区域自动气象站资料统计，有%s站小雨，%s站中雨，%s站大雨，%s站暴雨,%s站大暴雨。其中最大降雨量为%smm(%s)", strStartDate, resultList.size(), littleRain, middleRain, bigRain, hervyRain, hardRain, resultList.get(0).getRain(), resultList.get(0).getStationName());
                    }
                } else if (hervyRain != 0) {
                    if (!strStartDate.equals(strEndDate)) {
                        RainDisp = String.format("根据监测显示，时间:%s时至%s时,据全市%s个区域自动气象站资料统计，有%s站小雨，%s站中雨，%s站大雨，%s站暴雨。其中最大降雨量为%smm(%s)", strStartDate, strEndDate, resultList.size(), littleRain, middleRain, bigRain, hervyRain, resultList.get(0).getRain(), resultList.get(0).getStationName());

                    } else {
                        RainDisp = String.format("根据监测显示，时间:%s时,据全市%s个区域自动气象站资料统计，有%s站小雨，%s站中雨，%s站大雨，%s站暴雨。其中最大降雨量为%smm(%s)", strStartDate, resultList.size(), littleRain, middleRain, bigRain, hervyRain, resultList.get(0).getRain(), resultList.get(0).getStationName());

                    }
                } else if (bigRain != 0) {
                    if (!strStartDate.equals(strEndDate)) {
                        RainDisp = String.format("根据监测显示，时间:%s时至%s时,据全市%s个区域自动气象站资料统计，有%s站小雨，%s站中雨，%s站大雨。其中最大降雨量为%smm(%s)", strStartDate, strEndDate, resultList.size(), littleRain, middleRain, bigRain, resultList.get(0).getRain(), resultList.get(0).getStationName());

                    } else {
                        RainDisp = String.format("根据监测显示，时间:%s时,据全市%s个区域自动气象站资料统计，有%s站小雨，%s站中雨，%s站大雨。其中最大降雨量为%smm(%s)", strStartDate, resultList.size(), littleRain, middleRain, bigRain, resultList.get(0).getRain(), resultList.get(0).getStationName());
                    }
                } else if (middleRain != 0) {
                    if (!strStartDate.equals(strEndDate)) {
                        RainDisp = String.format("根据监测显示，时间:%s时至%s时,据全市%s个区域自动气象站资料统计，有%s站小雨，%s站中雨。其中最大降雨量为%smm(%s)", strStartDate, strEndDate, resultList.size(), littleRain, middleRain, resultList.get(0).getRain(), resultList.get(0).getStationName());

                    } else {
                        RainDisp = String.format("根据监测显示，时间:%s时,据全市%s个区域自动气象站资料统计，有%s站小雨，%s站中雨。其中最大降雨量为%smm(%s)", strStartDate, resultList.size(), littleRain, middleRain, resultList.get(0).getRain(), resultList.get(0).getStationName());

                    }
                } else if (littleRain != 0) {
                    if (!strStartDate.equals(strEndDate)) {
                        RainDisp = String.format("根据监测显示，时间:%s时至%s时,据全市%s个区域自动气象站资料统计，有%s站小雨。其中最大降雨量为%smm(%s)", strStartDate, strEndDate, resultList.size(), littleRain, resultList.get(0).getRain(), resultList.get(0).getStationName());

                    } else {
                        RainDisp = String.format("根据监测显示，时间:%s时,据全市%s个区域自动气象站资料统计，有%s站小雨。其中最大降雨量为%smm(%s)", strStartDate, resultList.size(), littleRain, resultList.get(0).getRain(), resultList.get(0).getStationName());

                    }
                } else {
                    if (!strStartDate.equals(strEndDate)) {
                        RainDisp = String.format("根据监测显示，时间:%s时至%s时,据全市%s个区域自动气象站资料统计，有%s站无雨。", strStartDate, strEndDate, resultList.size(), noRain);
                    } else {
                        RainDisp = String.format("根据监测显示，时间:%s时,据全市%s个区域自动气象站资料统计，有%s站无雨。", strStartDate, resultList.size(), noRain);
                    }
                }
                //第二步是  将前台传入的weatherByCondition数据渲染上表格
                result.add(RainDisp);
                request.getSession().setAttribute("rainQueryData", result);
            }

        } else {
            final String etype = elemType;
            //根据参数生成唯一MD5编码
            String rainSearchId = MD5Utils.MD5Encode(strStartDate + strEndDate + strCountys + type + element + elemType + valley, "utf-8");
            if (rainSearchId.equals(request.getSession().getAttribute("rainQueryData"))) {
                //已经进行过缓存了,直接读取缓存内容，没有缓存则进行查询
                result = (ArrayList) request.getSession().getAttribute("rainQueryData");
            } else {
                request.getSession().setAttribute("elemType", elemType);
                request.getSession().setAttribute("element", element);
                request.getSession().setAttribute("rainQueryId", rainSearchId);
                strCountys.split(",");
                Date startDate = DateTime.parseDateTime(strStartDate, "yyyy-MM-dd HH").toDate();
                Date endDate = DateTime.parseDateTime(strEndDate, "yyyy-MM-dd HH").toDate();
                if (elemType.equals("整点雨量")) {
                    elemType = "1小时雨量";
                }
                if (elemType.equals("预报雨量")) {
                    elemType = "1小时雨量";
                }
                if (elemType.equals("累积雨量")) {
                    elemType = "雨量";
                }
                ActualElemQuery elemQuery = new ActualElemQuery();
                elemQuery.setCountys(countys);
                elemQuery.setElement(element);
                elemQuery.setStartDate(startDate);
                elemQuery.setEndDate(endDate);
                elemQuery.setType(type);
                elemQuery.setRainFilter(rainFilter);
                List<ElemContourSet> contourSet = configService.getElemContourSet(elemType);
                //判断气象站
                List<ActualData> resultList = new ArrayList<>();
                if (!StringUtil.IsNullOrEmpty(qxstation) && qxstation.equals("1")) {
                    List<ActualData> qxResultList = skInfoService.qxElementQuery(elemQuery);
                    if (qxResultList != null && qxResultList.size() > 0) {
                        //阈值判断
                        if(!StringUtil.IsNullOrEmpty(rainFilter)){
                            for (ActualData actualData : qxResultList) {
                                if(actualData.getRain()>=Double.parseDouble(rainFilter)){
                                    resultList.add(actualData);
                                }
                            }
                        }else {
                            resultList = qxResultList;
                        }
                    }
                }
                if (weatherByCondition != null && resultList != null) {
                    if(!StringUtil.IsNullOrEmpty(rainFilter)){
                        for (WeatherVo weatherVo : weatherByCondition) {
                            if (Double.parseDouble(weatherVo.getRain()) >= Double.parseDouble(rainFilter)) {
                                ActualData actualData = new ActualData();
                                actualData.setLat(Double.valueOf(weatherVo.getLat()));
                                actualData.setLon(Double.valueOf(weatherVo.getLon()));
                                actualData.setRain(weatherVo.getRain() != null ? Double.valueOf(weatherVo.getRain()) : 0.0);
                                actualData.setStationId(weatherVo.getStationid());
                                actualData.setCounty(weatherVo.getAddvcd());
                                actualData.setStationName(weatherVo.getStationname());
                                resultList.add(actualData);
                            }
                        }
                    }else {
                        for (WeatherVo weatherVo : weatherByCondition) {
                            ActualData actualData = new ActualData();
                            actualData.setLat(Double.valueOf(weatherVo.getLat()));
                            actualData.setLon(Double.valueOf(weatherVo.getLon()));
                            actualData.setRain(weatherVo.getRain() != null ? Double.valueOf(weatherVo.getRain()) : 0.0);
                            actualData.setStationId(weatherVo.getStationid());
                            actualData.setCounty(weatherVo.getAddvcd());
                            actualData.setStationName(weatherVo.getStationname());
                            resultList.add(actualData);
                        }
                    }
                }

                String txtPath = "";
                //存放等值图地址
                if (!elemType.contains("能见度")) {
                    //生成等值图
                    if (equMap.equals("true")) {
                        Thread t = null;
                        List<ActualData> finalResultList = resultList;
                        txtPath = webRootKey2(finalResultList, contourSet, etype, request);
                    }
                    result.add(classifyElemByValue(resultList, contourSet, elemType));
                    result.add(contourSet);
                    String uniqueno = "";
                    if (!StringUtil.IsNullOrEmpty(txtPath)) {
                        //服务器地址
//                    DmServiceConnector conn = new DmServiceConnector("localhost", "6163");//改成181地址
                        if (conn != null) {
                            uniqueno = conn.getCallPlugin("ContourService.InterpolationService", "GetInterpolationWork",
                                    txtPath);
                        } else {
                            DmServiceConnector conn = new DmServiceConnector("localhost", "6163");
                            uniqueno = conn.getCallPlugin("ContourService.InterpolationService", "GetInterpolationWork",
                                    txtPath);
                        }
                        result.add(uniqueno);
                    }
                } else result.add("");
                String RainDisp = "";
                double Total = 0.0;
                double noRain = 0.0;
                int littleRain = 0;
                int middleRain = 0;
                int bigRain = 0;
                int hervyRain = 0;
                int hardRain = 0;
                int veryHardRain = 0;
                for (int i = 0; i < resultList.size(); i++) {
                    double rain = resultList.get(i).getRain();
                    if (rain >= 200) {
                        veryHardRain++;
                    } else if (rain >= 100) {
                        hardRain++;

                    } else if (rain >= 50) {
                        hervyRain++;
                    } else if (rain >= 25) {
                        bigRain++;
                    } else if (rain >= 10) {
                        middleRain++;
                    } else if (rain > 0) {
                        littleRain++;
                    } else {
                        noRain++;
                    }
                }
                if (veryHardRain != 0) {
                    if (!strStartDate.equals(strEndDate)) {
                        RainDisp = String.format("根据监测显示，时间:%s时至%s时,据全市%s个区域自动气象站资料统计，有%s站小雨，%s站中雨，%s站大雨，%s站暴雨,%s站大暴雨，%s站特大暴雨。其中最大降雨量为%smm(%s)", strStartDate, strEndDate, resultList.size(), littleRain, middleRain, bigRain, hervyRain, hardRain, veryHardRain, resultList.get(0).getRain(), resultList.get(0).getStationName());
                    } else {
                        RainDisp = String.format("根据监测显示，时间:%s时,据全市%s个区域自动气象站资料统计，有%s站小雨，%s站中雨，%s站大雨，%s站暴雨,%s站大暴雨，%s站特大暴雨。其中最大降雨量为%smm(%s)", strStartDate, resultList.size(), littleRain, middleRain, bigRain, hervyRain, hardRain, veryHardRain, resultList.get(0).getRain(), resultList.get(0).getStationName());

                    }
                } else if (hardRain != 0) {
                    if (!strStartDate.equals(strEndDate)) {
                        RainDisp = String.format("根据监测显示，时间:%s时至%s时,据全市%s个区域自动气象站资料统计，有%s站小雨，%s站中雨，%s站大雨，%s站暴雨,%s站大暴雨。其中最大降雨量为%smm(%s)", strStartDate, strEndDate, resultList.size(), littleRain, middleRain, bigRain, hervyRain, hardRain, resultList.get(0).getRain(), resultList.get(0).getStationName());

                    } else {
                        RainDisp = String.format("根据监测显示，时间:%s时,据全市%s个区域自动气象站资料统计，有%s站小雨，%s站中雨，%s站大雨，%s站暴雨,%s站大暴雨。其中最大降雨量为%smm(%s)", strStartDate, resultList.size(), littleRain, middleRain, bigRain, hervyRain, hardRain, resultList.get(0).getRain(), resultList.get(0).getStationName());
                    }
                } else if (hervyRain != 0) {
                    if (!strStartDate.equals(strEndDate)) {
                        RainDisp = String.format("根据监测显示，时间:%s时至%s时,据全市%s个区域自动气象站资料统计，有%s站小雨，%s站中雨，%s站大雨，%s站暴雨。其中最大降雨量为%smm(%s)", strStartDate, strEndDate, resultList.size(), littleRain, middleRain, bigRain, hervyRain, resultList.get(0).getRain(), resultList.get(0).getStationName());

                    } else {
                        RainDisp = String.format("根据监测显示，时间:%s时,据全市%s个区域自动气象站资料统计，有%s站小雨，%s站中雨，%s站大雨，%s站暴雨。其中最大降雨量为%smm(%s)", strStartDate, resultList.size(), littleRain, middleRain, bigRain, hervyRain, resultList.get(0).getRain(), resultList.get(0).getStationName());

                    }
                } else if (bigRain != 0) {
                    if (!strStartDate.equals(strEndDate)) {
                        RainDisp = String.format("根据监测显示，时间:%s时至%s时,据全市%s个区域自动气象站资料统计，有%s站小雨，%s站中雨，%s站大雨。其中最大降雨量为%smm(%s)", strStartDate, strEndDate, resultList.size(), littleRain, middleRain, bigRain, resultList.get(0).getRain(), resultList.get(0).getStationName());

                    } else {
                        RainDisp = String.format("根据监测显示，时间:%s时,据全市%s个区域自动气象站资料统计，有%s站小雨，%s站中雨，%s站大雨。其中最大降雨量为%smm(%s)", strStartDate, resultList.size(), littleRain, middleRain, bigRain, resultList.get(0).getRain(), resultList.get(0).getStationName());
                    }
                } else if (middleRain != 0) {
                    if (!strStartDate.equals(strEndDate)) {
                        RainDisp = String.format("根据监测显示，时间:%s时至%s时,据全市%s个区域自动气象站资料统计，有%s站小雨，%s站中雨。其中最大降雨量为%smm(%s)", strStartDate, resultList.size(), strEndDate, littleRain, middleRain, resultList.get(0).getRain(), resultList.get(0).getStationName());

                    } else {
                        RainDisp = String.format("根据监测显示，时间:%s时,据全市%s个区域自动气象站资料统计，有%s站小雨，%s站中雨。其中最大降雨量为%smm(%s)", strStartDate, resultList.size(), littleRain, middleRain, resultList.get(0).getRain(), resultList.get(0).getStationName());

                    }
                } else if (littleRain != 0) {
                    if (!strStartDate.equals(strEndDate)) {
                        RainDisp = String.format("根据监测显示，时间:%s时至%s时,据全市%s个区域自动气象站资料统计，有%s站小雨。其中最大降雨量为%smm(%s)", strStartDate, strEndDate, resultList.size(), littleRain, resultList.get(0).getRain(), resultList.get(0).getStationName());

                    } else {
                        RainDisp = String.format("根据监测显示，时间:%s时,据全市%s个区域自动气象站资料统计，有%s站小雨。其中最大降雨量为%smm(%s)", strStartDate, resultList.size(), littleRain, resultList.get(0).getRain(), resultList.get(0).getStationName());

                    }
                } else {
                    if (!strStartDate.equals(strEndDate)) {
                        RainDisp = String.format("根据监测显示，时间:%s时至%s时,据全市%s个区域自动气象站资料统计，有%s站无雨。", strStartDate, strEndDate, resultList.size(), noRain);
                    } else {
                        RainDisp = String.format("根据监测显示，时间:%s时,据全市%s个区域自动气象站资料统计，有%s站无雨。", strStartDate, resultList.size(), noRain);
                    }
                }
                //第二步是  将前台传入的weatherByCondition数据渲染上表格
                result.add(RainDisp);
                request.getSession().setAttribute("rainQueryData", result);
            }
        }
        return result;
    }

    /**
     * 雨量生成等值图文件
     *
     * @param resultList
     * @param contourSet
     * @param type
     * @param
     * @return
     */
    private String webRootKey1(List<ActualData> resultList, List<ElemContourSet> contourSet, String type, HttpServletRequest request) {
        List<ContoursData> contoursDataList = new ArrayList<ContoursData>();
        List<Equalline> equallineList = new ArrayList<Equalline>();
        String result = "";

        for (ActualData actualData : resultList) {
            ContoursData contoursData = new ContoursData();
            //这里使用经纬度的坐标
            contoursData.setX(actualData.getLon());
            contoursData.setY(actualData.getLat());
            if (type.indexOf("雨量") != -1) {
                contoursData.setVal(actualData.getRain());
            }
            if (type.indexOf("温度") != -1) {
                contoursData.setVal(actualData.getTemp());
            }
            if (type.indexOf("风") != -1) {
                contoursData.setVal(actualData.getWinds());
            }
            if (type.indexOf("湿") != -1) {
                contoursData.setVal(actualData.getHumid());
            }
            if (type.indexOf("气压") != -1) {
                contoursData.setVal(actualData.getPressure());
            }
            contoursDataList.add(contoursData);
        }
        for (ElemContourSet elemContourSet : contourSet) {
            Equalline equalline = new Equalline();
            equalline.setdValue(elemContourSet.getElementValue());
            equalline.setiColor(elemContourSet.getElementColor());
            equallineList.add(equalline);
        }
        try {
            String gridFile = DbConfig.TAB;
            //生成数据存入文档
            String path = request.getContextPath();
            String basePath = DbConfig.IP + path
                    + "/Temp/RainService/";
            String serviceUrl = basePath + "data.txt";
            String urlpath = request.getSession().getServletContext().getRealPath("/") + "Temp\\RainService\\";
            String serviceFilePath = urlpath + "data.txt";// 服务器文件
            FileUtil.mkDirs(urlpath);// 创建文件夹，生成多级目录
            result = SetParamToFile(contoursDataList, equallineList, gridFile, request, serviceUrl, serviceFilePath);
        } catch (Exception e) {
            e.printStackTrace();
        }
        return result;
    }

    /**
     * 气象多要素生成等值图文件
     *
     * @param resultList
     * @param contourSet
     * @param type
     * @param
     * @return
     */
    private String webRootKey2(List<ActualData> resultList, List<ElemContourSet> contourSet, String type, HttpServletRequest request) {
        List<ContoursData> contoursDataList = new ArrayList<ContoursData>();
        List<Equalline> equallineList = new ArrayList<Equalline>();
        String result = "";

        for (ActualData actualData : resultList) {
            ContoursData contoursData = new ContoursData();
            //这里使用经纬度的坐标
            contoursData.setX(actualData.getLon());
            contoursData.setY(actualData.getLat());
            if (type.indexOf("雨量") != -1) {
                contoursData.setVal(actualData.getRain());
            }
            if (type.indexOf("温度") != -1) {
                contoursData.setVal(actualData.getTemp());
            }
            if (type.indexOf("风") != -1) {
                contoursData.setVal(actualData.getWinds());
            }
            if (type.indexOf("湿") != -1) {
                contoursData.setVal(actualData.getHumid());
            }
            if (type.indexOf("气压") != -1) {
                contoursData.setVal(actualData.getPressure());
            }
            contoursDataList.add(contoursData);
        }
        for (ElemContourSet elemContourSet : contourSet) {
            Equalline equalline = new Equalline();
            equalline.setdValue(elemContourSet.getElementValue());
            equalline.setiColor(elemContourSet.getElementColor());
            equallineList.add(equalline);
        }
        try {
            String gridFile = DbConfig.TAB;
            //生成数据存入文档
            String path = request.getContextPath();
            String basePath = DbConfig.IP + path
                    + "/Temp/ElementService/";
            String serviceUrl = basePath + "data.txt";
            String urlpath = request.getSession().getServletContext().getRealPath("/") + "Temp\\ElementService\\";
            String serviceFilePath = urlpath + "data.txt";// 服务器文件
            FileUtil.mkDirs(urlpath);// 创建文件夹，生成多级目录
            result = SetParamToFile(contoursDataList, equallineList, gridFile, request, serviceUrl, serviceFilePath);
        } catch (Exception e) {
            e.printStackTrace();
        }
        return result;
    }

    //生成数据存入txt文档
    public String SetParamToFile(List<ContoursData> data, List<Equalline> equallineList, String gridFile, HttpServletRequest request, String serviceUrl, String serviceFilePath) throws IOException {
        FileWriter fw = new FileWriter(serviceFilePath);
        BufferedWriter bw = new BufferedWriter(fw);
        bw.write("[基本参数]");
        bw.newLine();
        bw.write(data.size() + "," + equallineList.size() + "," + gridFile + "," + 1 + "," + 1.5 + "," + 5 + "," + 1 + "," + 0 + "," + 0 + "," + 1);
        bw.newLine();
        bw.write("[数据]");
        bw.newLine();
        for (ContoursData datum : data) {
            //经纬度转墨卡托
//            DmMapPoint dt = transformService.LonLatConvertToMercator(datum.getX(), datum.getY());
            MapProjPara oldmpara = new MapProjPara();
            oldmpara.setpProjType((short) 1); //经纬度
            oldmpara.setpEarthParam((short) 12); //2000
            MapProjPara newmpara = new MapProjPara();
            newmpara.setpProjType((short) 5); //墨卡托
            newmpara.setpEarthParam((short) 7); //WGS-84
            newmpara.setPlat(0);
            newmpara.setpLon(0);
            MapProj mercator = new MapProj(oldmpara, newmpara);
            double[] xy = mercator.Convxy(datum.getX(), datum.getY());
            if (xy.length == 2) {
                DmMapPoint dt = new DmMapPoint(xy[0], xy[1]);
                bw.write(dt.x + "\t" + dt.y + "\t" + datum.getVal());
                bw.newLine();
            }
        }
        bw.write("[分级参数]");
        bw.newLine();
        for (Equalline equalline : equallineList) {
            bw.write(equalline.getdValue() + "," + equalline.getiColor() + "," + equalline.getiColor() + "," + 1 + "," + 0 + "," + equalline.getiColor() + "," + 0 + "," + 0 + "," + 0 + "," + 0);
            bw.newLine();
        }
        bw.close();
        fw.close();
        return serviceUrl;
    }


    /**
     * 初始化区域站统计页面
     * 2
     *
     * @return
     * @author dsq
     * @date 2018年7月12日
     */
    @RequestMapping("/initScaleChart")
    @ResponseBody
    public Object initScaleChart() {
        String quyuzhanTongJiList = "";
        List<SmallScaleStation> countyList = configService.getCitySta();
        List<SmallScaleStation> townList = configService.getTownStaList();
        for (SmallScaleStation countySta : countyList) {
            quyuzhanTongJiList += "<tr><td width=\"62\" valign='top'><a class=\"black\" style=\"text-decoration:none;\" href=\"javascript:void(0);\">";
            int j = 0;
            quyuzhanTongJiList += countySta.getCounty().trim() + "</a></td><td style=\"white-space:normal;\"><br/>";
            for (SmallScaleStation station : townList) {
                if (station.getCounty().equals(countySta.getCounty())) {
                    String checkstr = "";
                    if (station.getStationID().equals(countySta.getStationID())) {
                        checkstr = "checked='checked'";
                    }
                    if ((j + 1) % 2 == 0) {
                        quyuzhanTongJiList += "<input name=\"citys\" " + checkstr + " type=\"checkbox\" value=\""
                                + station.getStationID() + "\" />" + station.getStationName() + "<br/>";
                    } else {
                        quyuzhanTongJiList += "<input " + (j == 0 ? "checked" : "") + " name=\"citys\" " + checkstr
                                + " type=\"checkbox\" value=\"" + station.getStationID() + "\" />"
                                + station.getStationName() + " &nbsp;&nbsp;";
                    }
                    j++;
                }
            }
            quyuzhanTongJiList += "</td></tr>";
        }
        quyuzhanTongJiList = quyuzhanTongJiList.replaceFirst("<br/>", "");
        return quyuzhanTongJiList;
    }

    @RequestMapping("/initSChart")
    @ResponseBody
    public Object initSChart() {
        String quyuzhanTongJiList = "";
        List<SmallScaleStation> countyList = configService.getCitySta();
//        quyuzhanTongJiList += "</a></td><td style=\"white-space:normal;\"><br/>";
//        quyuzhanTongJiList += "<input id=\"all\" " + " type=\"checkbox\" value=\""
//                + "全选" + "\" />" + "反选" + "<br/>";
        if(countyList!=null&&countyList.size()>0) {
            for (int i = 0; i < countyList.size(); i++) {
                int j = 0;
                String checkstr = "checked='checked'";
                if (i == 0) {
                    quyuzhanTongJiList += "<input name=\"citys\" " + checkstr + " type=\"checkbox\" value=\""
                            + countyList.get(i).getStationID() + "\" />" + countyList.get(i).getStationName() + "<br/>";
                } else {
//                    quyuzhanTongJiList += "<input " + (i != 0 ? "checked" : "") + " name=\"citys\" " + checkstr
//                            + " type=\"checkbox\" value=\"" + countyList.get(i).getStationID() + "\" />"
//                            + countyList.get(i).getStationName() + " &nbsp;&nbsp;";
                    quyuzhanTongJiList += "<input name=\"citys\" " + checkstr + " type=\"checkbox\" value=\""
                            + countyList.get(i).getStationID() + "\" />" + countyList.get(i).getStationName() + "<br/>";
                }
                quyuzhanTongJiList += "</td></tr>";
            }
        }
//            quyuzhanTongJiList = quyuzhanTongJiList.replaceFirst("<br/>", "");
            return quyuzhanTongJiList;

    }

    /**
     * 添加雨量统计图
     * 2
     *
     * @param request
     * @param model
     * @return
     * @throws ParseException qxEltQuery
     * @author dsq
     * @date 2018年7月13日
     * String stations = request.getParameter("Stations");
     * String[] station = stations.split(",");
     */
    @RequestMapping("/addRainChart")
    @ResponseBody
    public Object addRainChart(HttpServletRequest request, Model model) throws ParseException {
        Date startDate = DateTime.parseDateTime(request.getParameter("startDate")).toDate();
        Date endDate = DateTime.parseDateTime(request.getParameter("endDate")).toDate();
        String stations = request.getParameter("citys");
        String element = request.getParameter("element");
        String stationid = request.getParameter("stationid");
        String chartType = request.getParameter("chartType");
        String daytype = request.getParameter("daytype");
        ActualElemQuery elemQuery = new ActualElemQuery();
        if (!StringUtil.IsNullOrEmpty(stations)) {
            String[] station = stations.split(",");
            if (station.length > 0) {
                elemQuery.setStations(Arrays.asList(station));
            }
        }
        elemQuery.setElement(element);
        elemQuery.setStartDate(startDate);
        elemQuery.setEndDate(endDate);
        elemQuery.setType(chartType);
        elemQuery.setStationid(stationid);
        elemQuery.setDaytype(daytype);
        List<ActualData> resultList = qxInfoService.qxEltQuery(elemQuery);
        // 处理成曲线图
        List<String> hours = new ArrayList<String>();
        Map<String, List<Double>> stationValMap = new HashMap<String, List<Double>>();
        for (ActualData actualData : resultList) {
            String stationName = actualData.getStationName().trim();
            if (stationName.equals(resultList.get(0).getStationName().trim())) {
                if (elemQuery.getDaytype() != null && elemQuery.getDaytype() != "") {
                    hours.add(new DateTime(actualData.getDateTime()).GetMonth() + "-" + new DateTime(actualData.getDateTime()).GetDay());
                } else {
                    hours.add(new DateTime(actualData.getDateTime()).GetHour() + "");
                }
            }
            double value = 0d;
            switch (element) {
                case "rain":
                    value = actualData.getRain();
                    break;
                case "temp":
                    value = actualData.getTemp();
                    break;
                case "winds":
                    value = actualData.getWinds();
                    break;
                case "humid":
                    value = actualData.getHumid();
                    break;
                case "visibility":
                    value = actualData.getVisibility();
                    break;
                case "pressure":
                    value = actualData.getPressure();
                default:
                    break;
            }
            if (!stationValMap.keySet().contains(stationName)) {
                List<Double> values = new ArrayList<Double>();

                values.add(value);
                stationValMap.put(stationName, values);
            } else {
                stationValMap.get(stationName).add(value);
            }
        }
        ArrayList<Object> result = new ArrayList<Object>();
        result.add(hours);
        for (String key : stationValMap.keySet()) {
            ArrayList<Object> tempArr = new ArrayList<Object>();
            tempArr.add(key);
            tempArr.add(stationValMap.get(key));
            result.add(tempArr);
        }
        return result;
    }

    /**
     * 自动站气象要素颜色归类
     * 2
     *
     * @param actualDatas
     * @param contourSets
     * @return
     * @author dsq
     * @date 2018年7月17日
     */
    public List<ActualData> classifyElemByValue(List<ActualData> actualDatas, List<ElemContourSet> contourSets,
                                                String elemType) {
        for (ActualData actualData : actualDatas) {
            double value = 0d;
            int color = 16777215;// 白色，默认颜色
            switch (elemType) {
                case "雨量":
                case "1小时雨量":
                case "3小时雨量":
                case "6小时雨量":
                case "12小时雨量":
                case "24小时雨量":
                    value = actualData.getRain();
                    break;
                case "温度":
                    value = actualData.getTemp();
                    break;
                case "风速":
                    value = actualData.getWinds();
                    break;
                case "湿度":
                    value = actualData.getHumid();
                    break;
                case "气压":
                    value = actualData.getPressure();
                default:
                    break;
            }
            for (int i = 0; i < contourSets.size(); i++) {
                ElemContourSet contourSet = contourSets.get(i);
                double level = contourSet.getElementValue();
                if (value >= level) {
                    color = contourSet.getElementColor();
                }
            }
            actualData.setColor(ColorUtil.transWin32ToHtml(color));
        }
        return actualDatas;
    }

    /**
     * 2
     * 初始化雷电预警
     *
     * @return
     */
    @RequestMapping("/initLDPage")
    @ResponseBody
    public Object initRaiden() {
        ArrayList<Object> arrayList = new ArrayList<Object>();
        ArrayList<String> nameList = new ArrayList<>();
        raidentemp newestDate = qxInfoService.getLDDate();
        // 加载列表
        DateTime dateTime = new DateTime(newestDate.getObservetime());
        String startTime = dateTime.AddHours(-1).toDateTimeString();
        String endTime = dateTime.toDateTimeString();
        //获取县级名称
        List<adminCode> adminCodeLs = configService.getTown();
        for (adminCode adminCodeL : adminCodeLs) {
            nameList.add(adminCodeL.getAdvname());
        }
        startTime="2024-04-12 00:00:00";
        endTime="2025-04-12 24:00:00";
        arrayList.add(startTime);
        arrayList.add(endTime);
        arrayList.add(nameList);
        return arrayList;
    }

    /**
     * 2
     * 雷电预警查询
     *
     * @param request
     * @param model
     * @return
     */
    @RequestMapping("/ThunderFcst")
    @ResponseBody
    public Object thunderFcst(HttpServletRequest request, Model model) {
        String time = request.getParameter("date");// 时间
        String sc = request.getParameter("sc");// 时次
        String sx = request.getParameter("sx");// 时效
        List<thunder_fcst> resultList = qxInfoService.getThunderFcst(time, sc, sx);// 查询潜势预报
        for (thunder_fcst thunder : resultList) {
            String ldLevel = thunder.getPredictlevel().toString().trim();
            Double predictprobability = thunder.getPredictprobability();
            predictprobability = (double) Math.round(predictprobability * 100) / 100;
            String imageName = "";
            Double dLightning = 0.0;// 雷电强度
            switch (ldLevel) {
                case "强":
                    imageName = "LevelFour";
                    dLightning = (double) 4;
                    break;
                case "中":
                    imageName = "LevelThree";
                    dLightning = (double) 3;
                    break;
                case "弱":
                    imageName = "LevelTwo";
                    dLightning = (double) 2;
                    break;
                case "无":
                    imageName = "LevelOne";
                    dLightning = (double) 1;
                    thunder.setPredictlevel("无预警");
                    break;
            }
            thunder.setPredictprobability(predictprobability);
            thunder.setImagename(imageName);
            thunder.setDlightning(dLightning);
        }
        return resultList;// 查询时间段内的预警信息号
    }


    /***2
     * 获取雷达图  最新十张   0.0
     * @param request
     * @param model
     * @return
     */
    @RequestMapping("/GetTenDoppler")
    @ResponseBody
    public Object GetTenDoppler(HttpServletRequest request, Model model) {
        Object list = qxInfoService.GetTenDoppler(request);
        return list;
    }

    /**
     * 2
     * 气象要素查询
     *
     * @param request
     * @param model
     * @return
     * @throws ParseException
     * @author dsq
     * @date 2018年7月11日
     */
    @RequestMapping("/YJrainQuery")
    @ResponseBody
    public Object YJrainQuery(HttpServletRequest request, Model model) throws ParseException {
        String lon = request.getParameter("lon");
        String lat = request.getParameter("lat");
        String r = request.getParameter("scope");
        DateTime now = DateTime.now();
        DateTime dateTime = now.AddDays(-1);
        String endDate1 = now.toDateTime();
        String startDate1 = dateTime.toDateTime();
        String endDate = now.toDateTime() + ":00:00";
        String startDate = dateTime.toDateTime() + ":00:00";
        List<MediumSmallScale> resultList1 = new ArrayList<MediumSmallScale>();
        List<msgmediumsmallscale> resultList = emergencyService.qxElementQuery(startDate, endDate);
        // 赋值
        try {
            if (resultList.size() > 0) {
                for (msgmediumsmallscale msg : resultList) {
                    Point2D center = new Point2D.Double(Double.parseDouble(lon), Double.parseDouble(lat));//
                    Point2D yidong = new Point2D.Double(msg.getLongitude(), msg.getLatitude());
                    if (getDistance(center, yidong) < Double.parseDouble(r)) {
                        MediumSmallScale smallscale = new MediumSmallScale();
                        smallscale.setStart(startDate1);
                        smallscale.setEnd(endDate1);
                        smallscale.setObservTime(msg.getObservtime());
                        smallscale.setStationID(msg.getStationid());
                        smallscale.setLongitude(msg.getLongitude());
                        smallscale.setLatitude(msg.getLatitude());
                        smallscale.setLon(msg.getLongitude());
                        smallscale.setLat(msg.getLatitude());
                        smallscale.setStationName(msg.getStationname());
                        smallscale.setRain(Float.parseFloat(String.format("%.1f", msg.getRain())));
                        smallscale.setDryBulbTemp(Float.parseFloat(String.format("%.1f", msg.getDrybulbtemp())));
                        smallscale.setInstantWindV(Float.parseFloat(String.format("%.1f", msg.getInstantwindv())));
                        smallscale.setRelHumidity(msg.getRelhumidity());
                        smallscale.setPressureSea(Float.parseFloat(String.format("%.1f", msg.getStationpress())));
                        smallscale.setCity(msg.getCity());
                        smallscale.setCounty(msg.getCounty());
                        DmMapPoint dt = transformService.LonLatConvertToLambert(msg.getLongitude(), msg.getLatitude());
                        smallscale.setX(dt.x);
                        smallscale.setY(dt.y);
                        resultList1.add(smallscale);
                    }
                }
            }
        } catch (Exception e) {
            // TODO: handle exception
        }
        return resultList1;
    }

    /**
     * 2
     * 初始化水库页面
     *
     * @param request
     * @param model
     * @return
     */
    @RequestMapping("/shuiKuInfo")
    @ResponseBody
    public Object getShuiKuInfo(HttpServletRequest request, Model model) {
        String sc = request.getParameter("sc");
        System.out.println(sc + "sc");
        System.out.println(qxInfoService.getShuiKuInfo() + "aaaa");
        return qxInfoService.getShuiKuInfo();
    }

    /**
     * 2
     * 初始化雷达马赛克页面
     *
     * @return
     */
    @RequestMapping("/initRadarMosaicPage")
    @ResponseBody
    public Object initRadarMosaicPage() {
        ArrayList<Object> arrayList = new ArrayList<Object>();
        // 获取时间
        Doppler dKey = qxInfoService.getRadarMosaicNewestDate();
        // 加载列表
        String timechar = dKey.getTimeChar();
        DateTime newestDateTime = new DateTime(dKey.getDateChar());
        newestDateTime = newestDateTime.AddHours(Integer.parseInt(timechar.substring(0, 2)));
        String startDate = newestDateTime.AddHours(-1).toDateTimeString();
        String endDate = newestDateTime.toDateTimeString();
        arrayList.add(startDate);// 时间
        arrayList.add(endDate);// 时间
        List<Doppler> dKey2 = qxInfoService.getRadarMosaicTypes();
        for (Doppler dop : dKey2) {
            dop.setType(dop.getType() + "|" + DbConfig.getRaderMosaicType(dop.getType()));
        }
        arrayList.add(dKey2);
        return arrayList;
    }

    /**
     * 2
     * 得到雷达马赛克信息
     *
     * @param request
     * @param model
     * @return
     * @throws ParseException 0.0
     */
    @RequestMapping("/getRadarMosaicInfo")
    @ResponseBody
    public Object getRadarMosaicInfo(HttpServletRequest request, Model model) throws ParseException {
        String startDate = request.getParameter("startDate");
        String endDate = request.getParameter("endDate");
        String type = request.getParameter("type");
        RadarSearch dKey = new RadarSearch();
        dKey.setStartDate(DateTime.parseDateTime(startDate).toDateTimeString());
        dKey.setEndDate(DateTime.parseDateTime(endDate).toDateTimeString());
        dKey.setType(type);
        List<Doppler> resultList = qxInfoService.getRadarMosaicInfo(dKey);
        String urlpath = request.getSession().getServletContext().getRealPath("/") + "Temp\\radarmosaic\\";
        FileUtil.mkDirs(urlpath);// 创建文件夹
        // 当图片达到1000张时清除
        FileUtil.ClearTempFiles(urlpath, 1000);

        for (Doppler doppler : resultList) {
            String fileName = DbConfig.getRadarMosaicFileName(doppler.getType(), doppler.getDateChar(), doppler.getTimeChar()) + ".png";
            SimpleDateFormat formatter = new SimpleDateFormat("yyyy年MM月dd日");
            String dateString = formatter.format(doppler.getDateChar()) + new StringBuffer(doppler.getTimeChar()).insert(2, "时").insert(5, "分");
            doppler.setRadTitle(dateString);
            String servicePath = urlpath + fileName;
            File serviceFile = new File(servicePath);
            if (serviceFile.exists()) {
                doppler.setJwImgPath("Temp\\radarmosaic\\" + fileName);
            } else {
                // 从mongdb获取图片
                Map<String, Object> map = new HashMap<String, Object>();
                map.put("dateyear", new DateTime(doppler.getDateChar()).toDateString().substring(0, 4));
                map.put("datechar", new DateTime(doppler.getDateChar()).toDateString());
                map.put("ldtype", doppler.getType());
                map.put("timechar", doppler.getTimeChar());
                map.put("collectionName", "zwld_file");
                byte[] data = ms.selectData(map);
                if (data != null) {
                    FileUtil.bytesToFile(data, servicePath);
                    doppler.setJwImgPath("Temp\\radarmosaic\\" + fileName);
                }
            }
            // 缓存到本地

        }
        // 拼接路径
        return resultList;
    }

    /**
     * 2
     * 获取水库或水电站坐标 f
     *
     * @param request
     * @param model
     * @return
     */
    @RequestMapping("/initLonlat")
    @ResponseBody
    public Object initLonlat(HttpServletRequest request, Model model) {
        String stationname = request.getParameter("stationname");
        List<String> lonlat = new ArrayList<>();
        if (stationname.contains("水库"))
            lonlat = qxInfoService.getReservoirLonlat(stationname);
        else if (stationname.contains("水电站"))
            lonlat = qxInfoService.getwatereleLonlat(stationname);
        else {//常德
//            lonlat.add("112.8167");
//            lonlat.add("27.8667");
            lonlat.add(DbConfig.X);
            lonlat.add(DbConfig.Y);
        }
        return lonlat;
    }

    /****2
     * 获得最近站点最新的实况信息
     * @param request
     * @param model
     * @return
     * @throws ParseException
     */
    @RequestMapping("/getNearStaMsg")
    @ResponseBody
    public Object getNearStaMsg(HttpServletRequest request, Model model) throws Exception {
        String lon = request.getParameter("lon");
        String lat = request.getParameter("lat");
        SmallScaleSearch selectKey = new SmallScaleSearch();// 查询类
        String startDate = request.getParameter("startDate");// 获取开始时间
        String stationID = qxInfoService.getStationid(lon, lat);
        selectKey.setStationID(stationID);
        selectKey.setStartDate(startDate);// 保存在selectKey中
        List<MediumSmallScale> resultList = skInfoService.getPoint(selectKey);
        for (MediumSmallScale msgMediumSmallScale : resultList) {
            DmMapPoint dt = transformService.LonLatConvertToLambert(msgMediumSmallScale.getLongitude(), msgMediumSmallScale.getLatitude());
            msgMediumSmallScale.setX(dt.x);
            msgMediumSmallScale.setY(dt.y);
        }
        return resultList;
    }

    /**
     * 通过AB点经纬度获取距离
     *
     * @param pointA A点(经，纬)
     * @param pointB B点(经，纬)
     * @return 距离(单位 ： 米)
     */
    Double getDistance(Point2D pointA, Point2D pointB) {
        double EARTH_RADIUS = 6371393; // 平均半径,单位：m
        // 经纬度（角度）转弧度。弧度用作参数，以调用Math.cos和Math.sin
        double radiansAX = Math.toRadians(pointA.getX()); // A经弧度
        double radiansAY = Math.toRadians(pointA.getY()); // A纬弧度
        double radiansBX = Math.toRadians(pointB.getX()); // B经弧度
        double radiansBY = Math.toRadians(pointB.getY()); // B纬弧度
        double cos = Math.cos(radiansAY) * Math.cos(radiansBY) * Math.cos(radiansAX - radiansBX)
                + Math.sin(radiansAY) * Math.sin(radiansBY);
        double acos = Math.acos(cos); // 反余弦值
        return EARTH_RADIUS * acos; // 最终结果
    }

    /**
     * 2
     *
     * @param request
     * @param model
     * @return
     * @throws ParseException
     */
    @RequestMapping("/qxWaringsksearch")
    @ResponseBody
    public Object qxWaringsksearch(HttpServletRequest request, Model model) throws ParseException {
        String strEndDate = request.getParameter("startDate");
        String strStartDate = request.getParameter("endDate");
        String type = request.getParameter("type");
        String element = request.getParameter("element");
        String elemType = "";
        List<Object> result = new ArrayList<>();
        //根据参数生成唯一MD5编码
        String rainSearchId = MD5Utils.MD5Encode(strStartDate + type + element, "utf-8");
        if (rainSearchId.equals(request.getSession().getAttribute("rainSearchId"))) {
            //已经进行过缓存了,直接读取缓存内容，没有缓存则进行查询
            result = (ArrayList) request.getSession().getAttribute("rainSearchData");
        } else {
            request.getSession().setAttribute("rainSearchId", rainSearchId);
            Date startDate = DateTime.parseDateTime(strStartDate).toDate();
            Date endDate = DateTime.parseDateTime(strEndDate).toDate();
            if (element.equals("整点雨量")) {
                elemType = "1小时雨量";
            }
            if (element.equals("rain")) {
                elemType = "雨量";
            }
            if (element.contains("temp")) {
                elemType = "温度";
            }
            if (element.contains("湿度")) {
                elemType = "湿度";
            }
            if (element.contains("wind")) {
                elemType = "风速";
            }
            if (element.contains("气压")) {
                elemType = "气压";
            }
            if (element.contains("能见度")) {
                elemType = "能见度";
            }
            ActualElemQuery elemQuery = new ActualElemQuery();
            elemQuery.setElement(element);
            elemQuery.setStartDate(startDate);
            elemQuery.setEndDate(endDate);
            elemQuery.setType(type);
            List<ActualData> resultList = forecastInfoService.qxWaringElementQuery(elemQuery);
            List<ElemContourSet> contourSet = configService.getElemContourSet(elemType);
            result.add(ClassifyElemByValue(resultList, contourSet, elemType));
            result.add(contourSet);
            request.getSession().setAttribute("rainSearchData", result);
        }

        return result;
    }

    /**
     * 自动站气象要素颜色归类
     * 2
     *
     * @param actualDatas
     * @param contourSets
     * @return
     * @author dsq
     * @date 2018年7月17日
     */
    public List<ActualData> ClassifyElemByValue(
            List<ActualData> actualDatas, List<ElemContourSet> contourSets, String elemType) {
        for (ActualData actualData : actualDatas) {
            double value = 0d;
            int color = 16777215; // 白色，默认颜色
            switch (elemType) {
                case "雨量":
                case "1小时雨量":
                case "3小时雨量":
                case "6小时雨量":
                case "12小时雨量":
                case "24小时雨量":
                    value = actualData.getRain();
                    break;
                case "温度":
                    value = actualData.getTemp();
                    break;
                case "风速":
                    value = actualData.getWinds();
                    break;
                case "湿度":
                    value = actualData.getHumid();
                    break;
                case "气压":
                    value = actualData.getPressure();
                case "能见度":
                    value = actualData.getVisibility();
                default:
                    break;
            }
            for (int i = 0; i < contourSets.size(); i++) {
                ElemContourSet contourSet = contourSets.get(i);
                double level = contourSet.getElementValue();
                if (value >= level) {
                    color = contourSet.getElementColor();
                }
            }
            actualData.setColor(ColorUtil.transWin32ToHtml(color));
        }
        return actualDatas;
    }

    /**
     * 2
     * 初始化气象服务网首页的左方小弹窗
     *
     * @return
     */
    @RequestMapping("/initScale")
    @ResponseBody
    public Object initScale() {
        ArrayList<Object> resultList = new ArrayList<Object>();
        // 时间
        String type = "SmallScale";
        collectTime scaleNewDate = qxInfoService.getScaleNewDate(type);
        StringBuilder dateTime = new StringBuilder();
        dateTime.append(scaleNewDate.getYear() + "-");
        dateTime.append(scaleNewDate.getMonth() + "-");
        dateTime.append(scaleNewDate.getDay() + " ");
        dateTime.append(scaleNewDate.getHour());
        resultList.add(dateTime.toString());
        // 区市
        List<adminCode> countyList = configService.getTown();//
        List<EasyuiTree> easyuiTrees = new ArrayList<EasyuiTree>();
        for (int i = 0; i < countyList.size(); i++) {
            EasyuiTree tree = new EasyuiTree();
            tree.setId(i + 1);
            tree.setChecked(true);
            tree.setText(countyList.get(i).getAdvname().trim());
            tree.setValue(countyList.get(i).getAdvcode().trim());
            easyuiTrees.add(tree);
        }
        resultList.add(easyuiTrees);
        // 站点
        List<SmallScaleStation> stationList = configService.getTownStaList();
        Map<String, List<SmallScaleStation>> countyMapStations = new HashMap<String, List<SmallScaleStation>>();
        List<SelectLink> selectLinks = new ArrayList<SelectLink>();
        for (SmallScaleStation station : stationList) {
            String county = station.getCounty();
            if (countyMapStations.containsKey(county)) {
                countyMapStations.get(county).add(station);
            } else {
                ArrayList<SmallScaleStation> arrayList = new ArrayList<SmallScaleStation>();
                arrayList.add(station);
                countyMapStations.put(county, arrayList);
            }
        }
        System.out.println(countyMapStations);
        for (String county : countyMapStations.keySet()) {
            SelectLink selectLink = new SelectLink();
            selectLink.setCounty(county);
            selectLink.setStations(countyMapStations.get(county));
            selectLinks.add(selectLink);
        }
        resultList.add(selectLinks);
        return resultList;
    }


    /* 2区市选择，获得（整点）雨量、温度、湿度、气压、风速 。。*/
    @RequestMapping("/getPoint")
    @ResponseBody
    public Object getPoint(HttpServletRequest request, Model model) throws Exception {
        SmallScaleSearch selectKey = new SmallScaleSearch();// 查询类
        String startDate = request.getParameter("startDate");// 获取开始时间
        String county = request.getParameter("county");
        String stationname = request.getParameter("stationname");
        if (!StringUtil.IsNullOrEmpty(county)) {
            String[] countys = county.split(",");
            selectKey.setCountys(Arrays.asList(countys));
        }
        selectKey.setType(stationname);
        selectKey.setStartDate(startDate);// 保存在selectKey中
        List<MediumSmallScale> resultList = skInfoService.getPoint(selectKey);
        for (MediumSmallScale msgMediumSmallScale : resultList) {
            DmMapPoint dmDot = new DmMapPoint(msgMediumSmallScale.getLongitude(), msgMediumSmallScale.getLatitude());
            DmMapPoint ltDot = transformService.LonLatConvertToLambert(dmDot.x, dmDot.y);
            msgMediumSmallScale.setX(ltDot.x);
            msgMediumSmallScale.setY(ltDot.y);
        }
        return resultList;
    }


    /**
     * 添加日均统计图
     * 2
     *
     * @param request
     * @param model
     * @return
     * @throws ParseException
     * @author dsq
     * @date 2018年7月13日
     */
    @RequestMapping(value = {"/addDayChart", "/addDayChart08", "/addDayChart20"})
    @ResponseBody
    public Object addDayChart(HttpServletRequest request, Model model) throws ParseException {
        Date startDate = DateTime.parseDate(request.getParameter("startDate")).toDate();
        Date endDate = DateTime.parseDate(request.getParameter("endDate")).toDate();
        String stations = request.getParameter("citys");
        String[] station = stations.split(",");
        String element = request.getParameter("element");
        String chartType = request.getParameter("chartType");
        if (request.getRequestURI().contains("/addDayChart08")) {
            String date1 = new DateTime().now().AddDays(-6).toDateString() + " 08:00:00";
            startDate = DateTime.parseDateTime(date1).toDate();
            String date2 = new DateTime().now().toDateString() + " 08:00:00";
            endDate = DateTime.parseDateTime(date2).toDate();
        } else if (request.getRequestURI().contains("/addDayChart20")) {
            String date1 = new DateTime().now().AddDays(-6).toDateString() + " 20:00:00";
            startDate = DateTime.parseDateTime(date1).toDate();
            String date2 = new DateTime().now().toDateString() + " 20:00:00";
            endDate = DateTime.parseDateTime(date2).toDate();
        }
        ActualElemQuery elemQuery = new ActualElemQuery();
        elemQuery.setStations(Arrays.asList(station));
        elemQuery.setElement(element);
        elemQuery.setStartDate(startDate);
        elemQuery.setEndDate(endDate);
        elemQuery.setType(chartType);
        elemQuery.setDaytype("日均");
        List<ActualData> resultList = skInfoService.qxElementQuery(elemQuery);
        // 处理成曲线图
        List<Integer> days = new ArrayList<Integer>();
        Map<String, List<Double>> stationValMap = new HashMap<String, List<Double>>();
        for (ActualData actualData : resultList) {
            String stationName = actualData.getStationName().trim();
            if (stationName.equals(resultList.get(0).getStationName().trim())) {
                days.add(new DateTime(actualData.getDateTime()).GetDay());
            }
            double value = 0d;
            switch (element) {
                case "rain":
                    value = actualData.getRain();
                    break;
                case "temp":
                    value = actualData.getTemp();
                    break;
                case "winds":
                    value = actualData.getWinds();
                    break;
                case "humid":
                    value = actualData.getHumid();
                    break;
                case "pressure":
                    value = actualData.getPressure();
                default:
                    break;
            }
            if (!stationValMap.keySet().contains(stationName)) {
                List<Double> values = new ArrayList<Double>();

                values.add(value);
                stationValMap.put(stationName, values);
            } else {
                stationValMap.get(stationName).add(value);
            }
        }
        ArrayList<Object> result = new ArrayList<Object>();
        result.add(days);
        for (String key : stationValMap.keySet()) {
            ArrayList<Object> tempArr = new ArrayList<Object>();
            tempArr.add(key);
            tempArr.add(stationValMap.get(key));
            result.add(tempArr);
        }
        return result;
    }

    /**
     * 2
     * 获取小时雨量图
     *
     * @param request
     * @param model
     * @return
     * @throws Exception
     */
    @RequestMapping("/getHourRain")
    @ResponseBody
    public Object getHourRain(HttpServletRequest request, Model model) throws Exception {
        List<MediumSmallScale> resultList = new ArrayList<MediumSmallScale>();
        SmallScaleSearch selectKey = new SmallScaleSearch();// 查询类
        String startDate = new DateTime(DateTime.now().AddHours(-1).toDate()).toDateTimeString();// 获取开始时间
        String endDate = new DateTime(DateTime.now().toDate()).toDateTimeString();// 获取开始时间
        selectKey.setStartDate(startDate);// 保存在selectKey中
        selectKey.setEndDate(endDate);// 保存在selectKey中
        MediumSmallScale result = skInfoService.getHourRain(selectKey);
        resultList.add(result);

        selectKey = new SmallScaleSearch();// 查询类
        startDate = new DateTime(DateTime.now().AddHours(-3).toDate()).toDateTimeString();// 获取开始时间
        endDate = new DateTime(DateTime.now().toDate()).toDateTimeString();// 获取开始时间
        selectKey.setStartDate(startDate);// 保存在selectKey中
        selectKey.setEndDate(endDate);// 保存在selectKey中
        MediumSmallScale result1 = skInfoService.getHourRain(selectKey);
        resultList.add(result1);

        selectKey = new SmallScaleSearch();// 查询类
        startDate = new DateTime(DateTime.now().AddHours(-6).toDate()).toDateTimeString();// 获取开始时间
        endDate = new DateTime(DateTime.now().toDate()).toDateTimeString();// 获取开始时间
        selectKey.setStartDate(startDate);// 保存在selectKey中
        selectKey.setEndDate(endDate);// 保存在selectKey中
        MediumSmallScale result2 = skInfoService.getHourRain(selectKey);
        resultList.add(result2);

        selectKey = new SmallScaleSearch();// 查询类
        startDate = new DateTime(DateTime.now().AddHours(-12).toDate()).toDateTimeString();// 获取开始时间
        endDate = new DateTime(DateTime.now().toDate()).toDateTimeString();// 获取开始时间
        selectKey.setStartDate(startDate);// 保存在selectKey中
        selectKey.setEndDate(endDate);// 保存在selectKey中
        MediumSmallScale result3 = skInfoService.getHourRain(selectKey);
        resultList.add(result3);

        selectKey = new SmallScaleSearch();// 查询类
        startDate = new DateTime(DateTime.now().AddHours(-24).toDate()).toDateTimeString();// 获取开始时间
        endDate = new DateTime(DateTime.now().toDate()).toDateTimeString();// 获取开始时间
        selectKey.setStartDate(startDate);// 保存在selectKey中
        selectKey.setEndDate(endDate);// 保存在selectKey中
        MediumSmallScale result4 = skInfoService.getHourRain(selectKey);
        resultList.add(result4);
        return resultList;
    }


    /***
     * 雨量 2
     * @param request
     * @param model
     * @return
     * @throws ParseException
     */
    @RequestMapping("/rain")
    @ResponseBody
    public Object rain(HttpServletRequest request, Model model) throws ParseException {
        Date startDate = null;
        Date endDate = null;
        if (StringUtil.IsNullOrEmpty(request.getParameter("startDate")) && StringUtil.IsNullOrEmpty(request.getParameter("endDate"))) {
            startDate = DateTime.parseDateTime(DateTime.now().AddHours(-23).toDateTimeString("yyyy-MM-dd HH:00:00")).toDate();
            endDate = DateTime.parseDateTime(DateTime.now().toDateTimeString("yyyy-MM-dd HH:00:00")).toDate();
        } else {
            startDate = DateTime.parseDateTime(request.getParameter("startDate")).toDate();
            endDate = DateTime.parseDateTime(request.getParameter("endDate")).toDate();
        }
        String elemType = request.getParameter("text");
        if (StringUtil.IsNullOrEmpty(elemType))
            elemType = "24小时雨量";
        String[] countys = new String[]{DbConfig.CITY + "市"};
        String type = "sum";
        String element = "rain";
        ActualElemQuery elemQuery = new ActualElemQuery();
        elemQuery.setCountys(Arrays.asList(countys));
        elemQuery.setElement(element);
        elemQuery.setStartDate(startDate);
        elemQuery.setEndDate(endDate);
        elemQuery.setType(type);
        List<ActualData> resultlst = new ArrayList<>();
        List<ActualData> resultList = skInfoService.qxElementQuery(elemQuery);//区域站
        List<ActualData> resultlist1 = skInfoService.slElementQuery(elemQuery);//雨量站
        for (ActualData data : resultList) {
            ActualData dd = new ActualData();
            data.setType("rain");
            dd = data;
            resultlst.add(dd);
        }
        for (ActualData data : resultlist1) {
            ActualData dd = new ActualData();
            dd = data;
            resultlst.add(dd);
        }
        List<ElemContourSet> contourSet = skInfoService.getElemContourSet(elemType);
        List<Object> result = new ArrayList<Object>();
        result.add(classifyElemByValue(resultList, contourSet, elemType));
        result.add(contourSet);
        return new ResultObj("查询成功", result, true);
    }

    /**
     * 水情 2
     *
     * @param request
     * @param model
     * @return
     */
    @RequestMapping("/waterQuery")
    @ResponseBody
    public Object waterQuery(HttpServletRequest request, Model model) {
        Date startDate = DateTime.now().AddHours(-1).toDate();
        Date endDate = DateTime.now().toDate();
        String countys = request.getParameter("countys");
        if (StringUtil.IsNullOrEmpty(countys))
            countys = DbConfig.COUNTY;
        Object resultList = skInfoService.waterQuery(startDate, endDate, countys);
        return resultList;
    }

    /***2
     * 飞行路线
     * @param request
     * @param model
     * @return
     */
    @RequestMapping("/GetFlypath")
    @ResponseBody
    public Object getFlyPath(HttpServletRequest request, Model model) {
        Object list = skInfoService.getFlypath(request);
        return list;
    }


    /****2
     * 获取云图   最新一张
     * @param request
     * @param model
     * @return
     */
    @RequestMapping("/GetNewestSatelliteNephoram")
    @ResponseBody
    public Object getNewestSatelliteNephoram(HttpServletRequest request, Model model) {
        Object list = skInfoService.getNewestSatelliteNephoram(request);
        return list;
    }

    /***2
     * 获取雷达图  最新一张
     * @param request
     * @param model
     * @return
     */
    @RequestMapping("/GetNewestDoppler")
    @ResponseBody
    public Object getNewestDoppler(HttpServletRequest request, Model model) {
        Object list = skInfoService.getNewestDoppler(request);
        return list;
    }

    /**
     * 得到最近站点的实况信息
     *
     * @return
     */
    @RequestMapping("/getSmallScaleByDistince")
    @ResponseBody
    public Object getSmallScaleByDistince(HttpServletRequest request, Model model) throws ParseException {
        String lon = request.getParameter("lon");
        String lat = request.getParameter("lat");
        Date newTime = qxInfoService.getScaleNewDate();

        return qxInfoService.getSmallScaleByDistince(newTime, lon, lat);
    }


    @RequestMapping("/GetJXHYBByPnt")
    @ResponseBody
    public Object GetJXHYBByPnt(HttpServletRequest request, Model model) throws ParseException {

        if (StringUtil.IsNullOrEmpty(request.getParameter("lon")) || StringUtil.IsNullOrEmpty(request.getParameter("lon")))
            return new ResultObj("查询失败", "参数异常", false);
        double lon = Double.valueOf(request.getParameter("lon"));
        double lat = Double.valueOf(request.getParameter("lat"));
        String type = request.getParameter("type");
        String datechar = request.getParameter("datechar");
        String timechar = qxInfoService.getJXHTimeChar(datechar);

        String path = request.getContextPath();
        String urlpath = request.getSession().getServletContext().getRealPath("/") + "Temp\\ForecastRain\\";// 临时文件目录
        FileUtil.mkDirs(urlpath);// 创建文件夹，生成多级目录
        FileUtil.ClearTempFiles(urlpath, 1000);// 清除缓存

        List<Map> result = new ArrayList<>();

        try {
            if (type.equals("3D")) {
                for (int i = 0; i < 24; i++) {
                    Map<String, Object> map = new HashMap<>();
                    String ntimes = String.format("%03d", (i + 1) * 3);
                    String ntimesGrid = String.format("%03d", i * 3);

                    SimpleDateFormat df = new SimpleDateFormat("yyyy-MM-dd HH:00:00");
                    Date time = df.parse(datechar + " " + timechar + ":00:00");
                    String format = df.format(time.getTime() + (i * 3) * 60 * 60 * 1000);
                    map.put("时间", format);

                    String filename = urlpath + timechar + ntimes + "ER03.grid";
                    File serviceFile = new File(filename);// 服务器文件
                    if (!serviceFile.exists()) {
                        Map<String, Object> mapfile = new HashMap<String, Object>();
                        mapfile.put("datechar", datechar);
                        mapfile.put("timechar", timechar);
                        mapfile.put("type", "ER03");
                        mapfile.put("ntimes", ntimesGrid);
                        mapfile.put("collectionName", "grid_file");
                        byte[] data = ms.selectData(mapfile);
                        if (data != null && !data.equals("")) {
                            FileUtil.bytesToFile(data, filename);
                        }
                    }
                    GridAnalysis gd = new GridAnalysis();
                    gd.openFile(filename);
                    double sum = 0;
                    if (serviceFile.exists()) {
                        sum = gd.getElevationAt(lon, lat);


                        map.put("累计雨量值", String.format("%.1f", sum));
                    }
                    if (i > 0) {
                        String filename1 = urlpath + timechar + ntimesGrid + "ER03.grid";
                        serviceFile = new File(filename1);// 服务器文件
                        if (!serviceFile.exists()) {
                            Map<String, Object> mapfile = new HashMap<String, Object>();
                            mapfile.put("datechar", datechar);
                            mapfile.put("timechar", timechar);
                            mapfile.put("type", "ER03");
                            mapfile.put("ntimes", String.format("%03d", (i - 1) * 3));
                            mapfile.put("collectionName", "grid_file");
                            byte[] data = ms.selectData(mapfile);
                            if (data != null && !data.equals("")) {
                                FileUtil.bytesToFile(data, filename);
                            }
                        }

                        if (serviceFile.exists()) {
                            GridAnalysis gg = new GridAnalysis();
                            gg.openFile(filename1);
                            gd.addGrid(gg);
                            double single = gd.getElevationAt(lon, lat);
                            map.put("雨量值", String.format("%.1f", single));
                        }
                    } else {
                        map.put("雨量值", String.format("%.1f", sum));
                    }
                    result.add(map);
                }
            } else if (type.equals("7D")) {
                for (int i = 0; i < 7; i++) {
                    Map<String, Object> map = new HashMap<>();
                    SimpleDateFormat df = new SimpleDateFormat("yyyy-MM-dd HH:00:00");
                    Date time = df.parse(datechar + " " + timechar + ":00:00");
                    String format = df.format(time.getTime() + (i * 24) * 60 * 60 * 1000);
                    map.put("时间", format);

                    int ntimes = (i + 1) * 24;

                    String filename = urlpath + timechar + String.format("%03d", ntimes) + "ER03.grid";
                    File serviceFile = new File(filename);// 服务器文件
                    if (!serviceFile.exists()) {
                        Map<String, Object> mapfile = new HashMap<String, Object>();
                        mapfile.put("datechar", datechar);
                        mapfile.put("timechar", timechar);
                        mapfile.put("type", "ER03");
                        mapfile.put("ntimes", String.format("%03d", ntimes - 3));
                        mapfile.put("collectionName", "grid_file");
                        byte[] data = ms.selectData(mapfile);
                        if (data != null && !data.equals("")) {
                            FileUtil.bytesToFile(data, filename);
                        }
                    }
                    GridAnalysis gd = new GridAnalysis();
                    gd.openFile(filename);
                    double sum = 0;
                    if (serviceFile.exists()) {
                        sum = gd.getElevationAt(lon, lat);
                        map.put("累计雨量值", String.format("%.1f", sum));
                    }

                    if (i > 0) {
                        String filename1 = urlpath + timechar + String.format("%03d", i * 24) + "ER03.grid";
                        serviceFile = new File(filename1);// 服务器文件
                        if (!serviceFile.exists()) {
                            Map<String, Object> mapfile = new HashMap<String, Object>();
                            mapfile.put("datechar", datechar);
                            mapfile.put("timechar", timechar);
                            mapfile.put("type", "ER03");
                            mapfile.put("ntimes", String.format("%03d", i * 24 - 3));
                            mapfile.put("collectionName", "grid_file");
                            byte[] data = ms.selectData(mapfile);
                            if (data != null && !data.equals("")) {
                                FileUtil.bytesToFile(data, filename);
                            }
                        }

                        if (serviceFile.exists()) {
                            GridAnalysis gg = new GridAnalysis();
                            gg.openFile(filename1);
                            gd.addGrid(gg);
                            double single = gd.getElevationAt(lon, lat);

                            map.put("雨量值", String.format("%.1f", single));
                        }
                    } else {
                        map.put("雨量值", String.format("%.1f", sum));
                    }
                    result.add(map);
                }
            }
        } catch (Exception ex) {
            return new ResultObj("查询失败", ex.getMessage(), false);
        }
        return new ResultObj("查询成功", result, true);
    }


    /****
     * 靶向发布 获取预估信息
     * type xz 行政区划    qx 圈选   kx 框选
     * @param request
     * @param model
     * @return
     */
    @RequestMapping("/GetEstimate")
    @ResponseBody
    public Object GetEstimate(HttpServletRequest request, Model model) {
        String type = request.getParameter("type");
        String cityCode = DbConfig.advCode;
        if (StringUtil.IsNullOrEmpty(cityCode)) return "城市编码不能为空!";
        UrlHttpRequest httpRequest = new UrlHttpRequest();
        Map<String, Object> data = new HashMap<>();
        String result = "";
        if (type.equals("xz")) {
            String disctrictsCode = request.getParameter("disctrictsCode");
            if (StringUtil.IsNullOrEmpty(disctrictsCode)) return "请传入行政编码!";
            data.put("disctrictsCode", disctrictsCode);
            data.put("cityCode", cityCode);
            Map<String, Object> parameters = new HashMap<>();
            parameters.put("code", "1000001");
            parameters.put("data", data);
            parameters.put("sign", SignatureUtil.getMD5Sign(data, DbConfig.bxfb_key));
            parameters.put("source", DbConfig.bxfb_source);
            result = httpRequest.httpPostBody(DbConfig.bxfb_key, JSON.toJSONString(parameters, SerializerFeature.DisableCircularReferenceDetect), "");
        } else if (type.equals("qx")) {
            String radius = request.getParameter("radius");
            if (StringUtil.IsNullOrEmpty(radius)) return "请传入半径!";
            String list = request.getParameter("list");
            if (StringUtil.IsNullOrEmpty(list)) return "请传入中心点，格式为 经度 伟度";
            data.put("mapType", "1");
            Integer num = list.split(",").length;
            if (num != 1) return "请传入一个点!";
            List<String> listArray = new ArrayList<>();
            for (Integer i = 0; i < num; i++) {
                listArray.add(list.split(",")[i].replace(" ", ","));
            }
            data.put("list", listArray);
            data.put("radius", radius);
            data.put("cityCode", cityCode);
            Map<String, Object> parameters = new HashMap<>();
            parameters.put("code", "1000002");
            parameters.put("data", data);
            parameters.put("sign", SignatureUtil.getMD5Sign(data, DbConfig.bxfb_key));
            parameters.put("source", DbConfig.bxfb_source);
            result = httpRequest.httpPostBody(DbConfig.bxfb_url, JSON.toJSONString(parameters, SerializerFeature.DisableCircularReferenceDetect), "");
        } else if (type.equals("kx")) {
            String list = request.getParameter("list");
            if (StringUtil.IsNullOrEmpty(list)) return "请传入点坐标，格式为经度 伟度,经度 伟度!";
            data.put("mapType", "2");
            Integer num = list.split(",").length;
            if (num < 3) return "请传入最少三个点!";
            List<String> listArray = new ArrayList<>();
            for (Integer i = 0; i < num; i++) {
                listArray.add(list.split(",")[i].replace(" ", ","));
            }
            data.put("list", listArray);
            data.put("cityCode", cityCode);
            Map<String, Object> parameters = new HashMap<>();
            parameters.put("code", "1000002");
            parameters.put("data", data);
            parameters.put("sign", SignatureUtil.getMD5Sign(data, DbConfig.bxfb_key));
            parameters.put("source", DbConfig.bxfb_source);
            result = httpRequest.httpPostBody(DbConfig.bxfb_url, JSON.toJSONString(parameters, SerializerFeature.DisableCircularReferenceDetect), "");
        }
        return JSONObject.parseObject(result);
    }

    /**
     * Description:查询 灾点根据唯一编号查询详情信息
     *
     * @param request
     * @return
     */
    @RequestMapping("/queryZhcxZhdXq")
    @ResponseBody
    public ResultObj queryZhcxZhdXq(HttpServletRequest request, Model model) {
        try {
            String wybh = request.getParameter("wybh");
            List<?> res = qxInfoService.queryZhcxZhdXq(wybh);
            if (res == null || res.size() == 0) {
                return new ResultObj("没有查询到结果！", null, true);
            } else {
                return new ResultObj("查询成功！", res, true);
            }

        } catch (Exception e) {
            e.printStackTrace();
            return new ResultObj(e.getMessage(), null, false);
        }
    }

    /**
     * 生成等值图
     *
     * @param request
     * @param model
     * @return
     */
    @RequestMapping("/getImageUrl")
    @ResponseBody
    public Object getImageUrl(HttpServletRequest request, Model model) {
        List<Object> result = new ArrayList<>();
        String uniqueno = request.getParameter("uniqueno");
        String x1 = request.getParameter("x1");
        String y1 = request.getParameter("y1");
        String x2 = request.getParameter("x2");
        String y2 = request.getParameter("y2");
        String width = request.getParameter("width");
        String height = request.getParameter("height");
//        DmServiceConnector conn = new DmServiceConnector("localhost", "6163");//改成181地址
        if (conn != null) {
            String imgurl = conn.getCallPlugin("ContourService.InterpolationService", "GetContourPic", uniqueno + "|" + DbConfig.TAB + "|" + width + "|" + height + "|" + x1 + "," + y1 + "," + x2 + "," + y2 + "|1");
            result.add(DbConfig.IMAGEURL + imgurl);
        } else {
            DmServiceConnector conn = new DmServiceConnector("localhost", "6163");
            String imgurl = conn.getCallPlugin("ContourService.InterpolationService", "GetContourPic", uniqueno + "|" + DbConfig.TAB + "|" + width + "|" + height + "|" + x1 + "," + y1 + "," + x2 + "," + y2 + "|1");
            result.add(DbConfig.IMAGEURL + imgurl);
        }
        return result;
    }

    /**
     * 生成等值图点坐标
     * @param
     * @param
     * @return
     */
    public Entites getPos(String posUrl) {
            String s = posUrl.toString();
            int i = s.indexOf("pos:");
            int j = s.indexOf("*");
            String pos = posUrl.toString().substring(i + 5, j);
            System.out.println(pos);
            String[] split = pos.split("#");
            String posColor = split[0];
            String[] posArr = split[1].split(",");
            ArrayList<MyPoint> myPoints = new ArrayList<MyPoint>();
            for (String s1 : posArr) {
                String[] ponit = s1.split(" ");
                MyPoint myPoint = new MyPoint(Double.parseDouble(ponit[0]), Double.parseDouble(ponit[1]));
                myPoints.add(myPoint);
            }
            Entites entites = new Entites();
            entites.setColor(posColor);
            entites.setPosArr(myPoints);
            return entites;
        }
}

